Java 启动jax rs服务器时出错

Java 启动jax rs服务器时出错,java,rest,jax-rs,Java,Rest,Jax Rs,尝试在本地启动web服务时出现以下错误 SEVERE: The ResourceConfig instance does not contain any root resource classes. com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes. at com.sun.jersey.server.

尝试在本地启动web服务时出现以下错误

SEVERE: The ResourceConfig instance does not contain any root resource classes.
com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.
    at com.sun.jersey.server.impl.application.RootResourceUriRules.<init>(RootResourceUriRules.java:99)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1359)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:180)
    at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:799)
    at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:795)
    at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:795)
    at com.sun.jersey.api.container.ContainerFactory.createContainer(ContainerFactory.java:172)
    at com.sun.jersey.api.container.ContainerFactory.createContainer(ContainerFactory.java:264)
    at com.sun.jersey.api.container.ContainerFactory.createContainer(ContainerFactory.java:246)
    at com.sun.jersey.api.container.httpserver.HttpServerFactory.create(HttpServerFactory.java:117)
    at com.sun.jersey.api.container.httpserver.HttpServerFactory.create(HttpServerFactory.java:92)
    at com.swiped.main.ServerStart.main(ServerStart.java:14)
我的web xml如下所示

public class ExposedFunctions {

    private static Logger logger = Logger.getLogger(ExposedFunctions.class);
    private DBFactoryController controller = new DBFactoryController();

    public ExposedFunctions(){
        if(controller!= null){
            controller.buildCache();
        }
    }

    @GET
    @Path("/add/{username}/{password}/{email}/{firstname}/{lastname}")
    @Produces(MediaType.TEXT_PLAIN)
    public String register(@PathParam("username") String username, @PathParam("password") String password, @PathParam("email") String email, @PathParam("firstname") String firstname, @PathParam("lastname") String lastname) {
        if(StringUtilities.stringEmptyOrNull(username, password, email, firstname, lastname)){
            logger.error("String was null or empty when registering");
        }

        RegistrationStatus status = controller.register(username, password, email, firstname, lastname);
        return status.getValue();
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>com.swiped.service</display-name>
  <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>com.swiped.service</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/rest/*</url-pattern>
  </servlet-mapping>
</web-app> 
@SuppressWarnings("restriction")
public static void main(String[] args){
    try{
        HttpServer server = HttpServerFactory.create(BASE_URI);
        server.start();
        System.out.println("Press Enter to stop the server. ");
        System.in.read();
        server.stop(0);
    }catch(Exception e){
        e.printStackTrace();
    }
}
我注意到很多人都犯过类似的错误,但是针对个人情况给出了很多不同的建议,这使得我很难找到解决这个错误的方法。是否有人认为我的方法有任何明显的错误,如果有,请您帮助我解决它


感谢您抽出时间

也用
@Path
注释
公开的函数

@Path("/")
public class ExposedFunctions {
编辑:类是根资源,而方法是子资源。你必须两者兼得