Spring Data使Spring无法找到JAXRS的@Provider? [英] Spring Data makes spring unable to find JAXRS's @Provider?
问题描述
我正在使用Spring + Jersey来构建API服务. 最近,我尝试将Spring Data合并到服务器中. 我没有在运行的代码中真正使用任何存储库,只需在app.xml中添加一行:
I am using Spring + Jersey to build an API service . Recently , I try to incorporate Spring Data to my server . I haven't truly use any Repositories in my running code , just add one line in my app.xml :
<jpa:repositories base-package="destiny.web" entity-manager-factory-ref="entityManagerFactoryApp" />
但是!我注意到我的API无法正常工作,抱怨"找不到Java类xxx和Java类型xxx的消息正文编写器,并且未找到MIME媒体类型application/json "
But ! I notice my API not working , complaining "A message body writer for Java class xxx , and Java type class xxx , and MIME media type application/json was not found"
如果我删除xml中的"jpa:repositories ..."行,则一切正常! 和,所有提供程序类都在spring之前注册:
If I remove the "jpa:repositories ..." line in my xml , everything works fine ! and , all provider classes are registered by spring :
{http://*:8080-1} Registering Spring bean, apiResultJsonWriter, of type destiny.web.api.ApiResultJsonWriter as a provider class
{http://*:8080-1} Registering Spring bean, webApi, of type destiny.web.api.WebApi as a root resource class
{http://*:8080-1} Initiating Jersey application, version 'Jersey: 1.8 06/24/2011 12:17 PM'
但是,如果我在XML中添加"jpa:repositories ..."行,则只会注册根资源类":
But , if I add "jpa:repositories..." line in my XML , only "root resources class" are registered :
{http://*:8080-1} CDI support is enabled
{http://*:8080-1} Using default applicationContext
{http://*:8080-1} Registering Spring bean, webApi, of type destiny.web.api.WebApi as a root resource class
{http://*:8080-1} Initiating Jersey application, version 'Jersey: 1.8 06/24/2011 12:17 PM'
所有 JAXRS的@Provider 都丢失了!
我不知道这是否是Spring-Data的错误吗? 以及如何解决呢?
I don't know if it is Spring-Data's bug ? And how to solve it ?
环境:
spring-3.1
jersey-core-1.8.jar
jersey-server-1.8.jar
jersey-spring-1.8.jar
spring-data-jpa-1.0.3.RELEASE.jar
spring-data-commons-core-1.1.0.RELEASE.jar
服务器:resin-4.0.25
相关依赖项:
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.8</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-spring</artifactId>
<version>1.8</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.0.3.RELEASE</version>
</dependency>
(我尝试添加jersey-json,但仍然无法正常工作)
( I tried to add jersey-json , but still not working )
推荐答案
您需要注册包含以@Provider
在Jersey 2中,这是通过调用ResourceConfig
类中的packages方法来完成的.
in Jersey 2 this is done via by calling the packages method in your ResourceConfig
class.
我相信您还可以在servlet上放上basepackages属性.在此处查看在春季使用CXF自动发现JAX-RS资源应用程序
I believe there is also a basepackages attribue you can put on the servlet. See here Autodiscover JAX-RS resources with CXF in a Spring application
这篇关于Spring Data使Spring无法找到JAXRS的@Provider?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!