Benny Iskandar
Benny Iskandar

Reputation: 121

JAX-RS with Jersey 2.22.2 + Tomcat 7.0.59 : The requested resource is not available

I have built separated rest-model library and when the jersey do the resource config packages , seems doesn't work and it will response The requested resource is not available.

I have used : Jersey 2.22.2 and Tomcat 7.0.59

And please find the following details below :

rest-model.jar (file)
  > com.company.rest.domain.* (package)
    > TestData.class (file)
      > @XmlRootElement
      > class TestData {
      >   private String str ;
      >   public TestData() {}
      >   public TestData(String str) { setStr(str); }
      >   public String getStr() { return str ; } 
      >   public void setStr(String str) { this.str = str ; }
      > }
  > com.company.rest.service.* (package)
    > TestService.class (file)
      > @Path("/test")
      > @Produces({MediaType.APPLICATION_JSON})
      > class TestService {
      >   @GET public TestData test() {
      >     return new TestData("test") ;
      >   }
      > }

Tomcat with classpath to file rest-model.jar
WebRoot (folder)
  > WEB-INF (folder)
    > web.xml (file)
      <servlet>
        <servlet-name>RestApp</servlet-name>
        <servlet-class>
          org.glassfish.jersey.servlet.ServletContainer
        </servlet-class>
        <init-param>
          <param-name>
            com.sun.jersey.config.property.packages
          </param-name>
          <param-value>
            com.company.rest.service
          </param-value>
        </init-param>
      </servlet>
      <servlet-mapping>
        <servlet-name>RestApp</servlet-name>
        <url-pattern>/rest/*</url-pattern>
      </servlet-mapping>

Upvotes: 2

Views: 203

Answers (2)

Kishore Bandi
Kishore Bandi

Reputation: 5721

The init-param used for package scanning is wrong.

For Jersey 2.XX, you need to configure it as:

<init-param>
    <param-name>jersey.config.server.provider.packages</param-name>
    <param-value>com.company.rest.service</param-value>
</init-param>

Upvotes: 1

Hervian
Hervian

Reputation: 1076

If you navigate to your tomcat folder, specifically the configuration file conf/server.xml, does the tag in the bottom look as you expect? It might be that you are simply requesting the wrong URL (missing a base path) - see what the server.xml file tells you about the path to your web app.

In Eclipse, you will have server pane with two sub panes: Overview and Modules. The modules shows your web app, and the base paths.

Upvotes: 0

Related Questions