Наследование аннотаций для JAX-RS не работает

отдых-сервер.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. Может ли кто-нибудь помочь мне в этом.


person vivek    schedule 23.09.2013    source источник
comment
Я не уверен, что вам разрешено полностью опускать аннотацию @Produces. Он является наследственным.   -  person Donal Fellows    schedule 23.09.2013
comment
Я отредактировал свой вопрос. Не могли бы вы указать, где я ошибаюсь   -  person vivek    schedule 23.09.2013
comment
Вы когда-нибудь получали ответ на этот вопрос? Я сталкиваюсь с той же проблемой.   -  person user489041    schedule 18.09.2014
comment
Пробовали ли вы переместить уровень класса @Path с CatalogServiceImpl на CatalogService?   -  person bdkosher    schedule 19.09.2014


Ответы (1)


Адрес создается следующим образом:

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

ваш адрес указан неверно.

Допустим, ваш веб-контекст — это myApp, а URL-шаблон вашего сервлета — /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
person Jeff Wang    schedule 19.09.2014
comment
Кроме того, нашел объяснение этому на страницах cxf: cxf. apache.org/docs/jax-rs.html#JAX-RS-HowRequestURIisMatched - person Jeff Wang; 19.09.2014