【问题标题】:Annotation inheritance for JAX-RS not workingJAX-RS 的注释继承不起作用
【发布时间】:2013-09-28 03:22:39
【问题描述】:

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>

界面:

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/categories has found, Relative Path: /categories 异常。谁能帮我解决这个问题。

【问题讨论】:

  • 我不确定您是否可以完全省略 @Produces 注释。它可继承的。
  • 我已经编辑了我的问题。你能指出我错在哪里吗
  • 曾经得到这个答案吗?我遇到了同样的问题。
  • 您是否尝试过将班级级别的@PathCatalogServiceImpl 移动到CatalogService

标签: java cxf jax-rs cxfrs


【解决方案1】:

地址结构如下:

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

您的地址设置不正确。

假设你的 web context 是 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 元素上设置一个地址,仅在版本控制时,或者当我出于某种原因实际上需要多个 rest 服务器时。大多数时候我将地址设置为“”。

编辑:或者,如果您愿意:

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

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2014-11-13
  • 1970-01-01
  • 2015-02-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-22
  • 1970-01-01
相关资源
最近更新 更多