com.sun.jersey.api.container.ContainerException:ResourceConfig实例不包含任何根资源类

时间:2018-08-17 06:49:13

标签: jersey jax-rs

我尝试在Google上进行搜索,但未能解决此问题。

我正在尝试在我的Jsf应用程序中添加Rest-Api。例如,如果我致电http://localhost:5080/ApplicationFormFillingProcess-portlet/api/requirements 我想返回JSON数据。

为处理这些请求,我在web.xml文件中添加了一个servlet。所以现在我的 web.xml 文件看起来像这样:-

<?xml version="1.0"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <context-param>
        <param-name>com.sun.faces.expressionFactory</param-name>
        <param-value>org.jboss.el.ExpressionFactoryImpl</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Production</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
        <param-value>-1</param-value>
    </context-param>
    <context-param>
        <param-name>primefaces.THEME</param-name>
        <param-value>redmond</param-value>
    </context-param>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet>
        <servlet-name>jersey-serlvet</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.infinite.npsc.Controller</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>jersey-serlvet</servlet-name>
        <url-pattern>/api/*</url-pattern>
    </servlet-mapping>

</web-app>

我有Controller.java类,它是请求范围的bean。在此类中,我定义了一种方法:-即

@Path("/api/requirements/")
    @POST
    @Produces(MediaType.APPLICATION_JSON)
    public TokenAndEbp getRequirementDetails(){

        final String loginUrl = "https://testserver.com/test/login";

        Client client = Client.create();

        WebResource webResource = client
           .resource(loginUrl);

        String input = "{\"username\":\"210003501a\",\"password\":\"123\"}";

        ClientResponse response = webResource.type("application/json")
           .post(ClientResponse.class, input);

        System.out.println("Output from Server .... \n");
        System.out.println("the response code is:- "+response.getStatus());
        String output = response.getEntity(String.class);
        System.out.println(output);

        String token = response.getHeaders().getFirst("Authorization");
        System.out.println(token);

        TokenAndEbp tkp = new TokenAndEbp();
        tkp.setToken(token);
        tkp.setEbpCode("54454");
        return tkp;

    }

现在我从邮递员http://localhost:5080/ApplicationFormFillingProcess-portlet/api/requirements打电话

它只是显示错误:-

com.sun.jersey.api.container.ContainerException:
The ResourceConfig instance does not contain any root resource classes.

我当前使用的依赖项列表是:-

jersey-client-1.8
jersey-core-1.8
jersey-server-1.8

0 个答案:

没有答案