3

休息服务器.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,我得到 No root resource matching request path /myfashions/catalog/categorieshas found, Relative Path:/categories异常。谁可以帮我这个事。

4

1 回答 1

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
于 2014-09-19T18:14:20.570 回答