0
votes

All, I am trying to write a project using the java restful service by jersey. I get problems "The ResourceConfig instance does not contain any root resource classes". I've tried all solutions from here and it didn't work.

  1. I create a new project named "test"

  2. The web.xml is :

    <servlet>
        <servlet-name>Jersey REST Service</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>test</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Jersey REST Service</servlet-name>
        <url-pattern>/api/*</url-pattern>
    </servlet-mapping>
    
  3. A simple service:

    @Path("/message")
    public class MessageRestService {
    
    }
    
  4. Also I change the classes built path into /WEB-INF/classes

And I start the project in tomcat 7 also tried 8, the problem is still there

1

1 Answers

0
votes

Can you try this. Please modify your package store that rest service

    <!-- JAX-RS -->  
    <servlet>
        <servlet-name>RestServlet</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>the package you store</param-value>
        </init-param>
        <init-param>
    <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
    <param-value>true</param-value>
</init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <!-- JAX-RS -->
    <servlet-mapping>
        <servlet-name>RestServlet</servlet-name>
        <url-pattern>/api/*</url-pattern>
    </servlet-mapping>