简体   繁体   English

CXF + Spring:找不到根资源匹配请求路径

[英]CXF + Spring: No root resource matching request path has been found

Trying to get a REST service with CXF and Spring up and running and I hit this wall. 试图通过CXF和Spring启动并运行REST服务,我碰到了这堵墙。 Everything else looks fine since I can access my /services/ page and see MyService listed under the REST services. 因为我可以访问/ services /页面并查看REST服务下列出的MyService,所以其他所有内容看起来都不错。 I can view the WADL of the service just fine, with my method appearing there. 我可以在其中看到我的方法,从而很好地查看服务的WADL。 When I try to access it though, exception occurs. 但是,当我尝试访问它时,会发生异常。

WARNING: No root resource matching request path /testApp/services/MyService/goTest has been found, Relative Path: /goTest. Please enable FINE/TRACE log level for more details.
Jul 19, 2016 4:30:50 PM org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper toResponse
WARNING: javax.ws.rs.NotFoundException: HTTP 404 Not Found

My service interface 我的服务界面

@Path("/MyService")
@Service
public interface MyService {

    @GET
    @Path("/goTest")
    @Produces(MediaType.APPLICATION_JSON)
    public Response testService();
}

Service implementation: 服务实施:

public class MyServiceImpl implements MyService {

public Response testService() {
        // Code

        return Response.status(200).entity(gson.toJson(json)).build();
    }
}

Configuration class: 配置类:

 @Configuration
 public class WebServiceSpringConfig {

    @Bean(name=Bus.DEFAULT_BUS_ID)
        public SpringBus springBus() {
            return new SpringBus();
        }


        @Bean
        public Server MyService() {

            JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean();
            endpoint.setBus(springBus());
            endpoint.setAddress("/MyService");
            endpoint.setServiceBean(new MyServiceImpl());
            return endpoint.create();
        }
    }

Spring config and CXF servlet are declared in the web.xml Spring config和CXF servlet在web.xml中声明

I'm using Spring 4.2.0 with CXF 3.1.4 我在CXF 3.1.4中使用Spring 4.2.0

Your url goTest could be access as shown below. 您的网址goTest可以如下所示进行访问。

http://<ip-add>:<port>/<web-root>/services/MyService/MyService/goTest

in short add MyService again as you have set MyService as setAddress and also as @Path 简而言之,当您将MyService设置为setAddress以及@Path再次添加MyService

/testApp/services/MyService/MyService/goTest

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM