休息-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>
接口:
public interface CatalogService {
@Path("/categories")
@GET
@Produces({MediaType.APPLICATION_JSON})
SelectCategoryBeanList getMyfashionCategories();
}
类别:
@Service
@Path("/myfashions/catalog")
public class CatalogServiceImpl implements CatalogService {
@Override
public SelectCategoryBeanList getMyfashionCategories() {
...
...
}
}
当我调用http://localhost:8080/myfashions/catalog/categories
时,我找不到根资源匹配请求路径/myfashions/catalog/categories
,相对路径:/categories
异常。任何人都可以帮助我。
答案 0 :(得分:0)
地址构造如下:
http(s)://<host>:<port>/<webapp>/<servlet URL-pattern>/<jaxrs:server address>/<resources>
您的地址设置不正确。
假设你的web上下文是myApp,而你的servlet url-pattern是/ rest / *,来完成
http://localhost:8080/myApp/rest/myfashions/catalog/categories
你需要:
webapp name = myApp
servlet url-pattern = /rest/*
jaxrs:server address = myfashions
@Path on the class = /catalog
@Path on the interface (on the method) = /categories
我通常只在版本控制时在jaxrs:server元素上设置一个地址,或者当我因任何原因实际需要多个休息服务器时。大多数时候我将地址设置为“”。
编辑:或者,如果你想:
http://localhost:8080/myfashions/catalog/categories
你需要:
webapp name = myfashions
servlet url-pattern = /*
jaxrs:server address = ""
@Path on the class = /catalog
@Path on the interface (on the method) = /categories