3

rest-server.xml:

<jaxrs:server id="baseApi" address="http://localhost:8080/myfashions/catalog">
    <jaxrs:serviceBeans>
        <bean class="com.myfashions.api.service.rest.implementation.CatalogServiceImpl"/>
    </jaxrs:serviceBeans>
    <jaxrs:providers>
        <ref bean="customRequestHandler"/>
        <ref bean="customResponseHandler"/>
        <ref bean="restExceptionMapper"/>
        <bean class="org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider"/>
    </jaxrs:providers>
</jaxrs:server>

Interface:

public interface CatalogService {

    @Path("/categories")
    @GET
    @Produces({MediaType.APPLICATION_JSON})
    SelectCategoryBeanList getMyfashionCategories();
}

Class:

@Service
@Path("/myfashions/catalog")
public class CatalogServiceImpl implements CatalogService {
    @Override
    public SelectCategoryBeanList getMyfashionCategories() {
        ...
        ...
    }
}

When I called http://localhost:8080/myfashions/catalog/categories, I got No root resource matching request path /myfashions/catalog/categories has been found, Relative Path: /categories exception. Can anyone help me on this.

vivek
  • 4,599
  • 3
  • 25
  • 37

1 Answers1

0

The address is contructed like :

http(s)://<host>:<port>/<webapp>/<servlet URL-pattern>/<jaxrs:server address>/<resources>

your address setting is incorrect.

Let's say your web context is myApp, and your servlet url-pattern is /rest/*, to accomplish

http://localhost:8080/myApp/rest/myfashions/catalog/categories

you would need:

webapp name = myApp
servlet url-pattern = /rest/*
jaxrs:server address = myfashions
@Path on the class = /catalog
@Path on the interface (on the method) = /categories

I typically set an address on the jaxrs:server element only when versioning, or when I actually want multiple rest servers for whatever reason. Most of the time I set the address as "".

Edit: Alternatively, if you want:

http://localhost:8080/myfashions/catalog/categories

you would need:

webapp name = myfashions
servlet url-pattern = /*
jaxrs:server address = ""
@Path on the class = /catalog
@Path on the interface (on the method) = /categories
Jeff Wang
  • 1,837
  • 1
  • 15
  • 29
  • Also, found the explanation for this on the cxf pages: http://cxf.apache.org/docs/jax-rs.html#JAX-RS-HowRequestURIisMatched – Jeff Wang Sep 19 '14 at 18:23