简体   繁体   中英

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. Everything else looks fine since I can access my /services/ page and see MyService listed under the REST services. I can view the WADL of the service just fine, with my method appearing there. 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

I'm using Spring 4.2.0 with CXF 3.1.4

Your url goTest could be access as shown below.

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

/testApp/services/MyService/MyService/goTest

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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