JavaSpring配置和Resteasy

JavaSpring配置和Resteasy,spring,resteasy,Spring,Resteasy,我正试图把Resteasy和Spring结合起来;我已经关注了Resteasy的文档和这篇文章:。 我在rest类上使用@Autowire或其他Spring注释,但我希望这样做,使我的rest类不受Spring(或DI)依赖。 我还希望仅通过java配置来配置spring。在spring配置中,我添加了以下内容: <context:component-scan base-package="package.where.spring.configuration.beans.are , pack

我正试图把Resteasy和Spring结合起来;我已经关注了Resteasy的文档和这篇文章:。 我在rest类上使用@Autowire或其他Spring注释,但我希望这样做,使我的rest类不受Spring(或DI)依赖。 我还希望仅通过java配置来配置spring。在spring配置中,我添加了以下内容:

<context:component-scan base-package="package.where.spring.configuration.beans.are , package.where.rest.classes.are">
<context:include-filter type="annotation" expression="javax.ws.rs.Path"/>
</context:component-scan>

当然,我在web.xml中也有,因此SpringContextLoaderListener将获取spring配置:

<context-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>classpath:/spring-config.xml</param-value>
</context-param>

上下文配置位置
类路径:/spring-config.xml
删除@Autowire注释,如果我也删除了第一个包(我通过SpringJava配置配置了注入),则不会发生注入,字段保持为空;如果删除第二个包,resteasy将无法识别rest类的URL

我想在Spring配置中配置注入,有没有办法让resteasy识别外部配置的SpringBean的路径

编辑:我注意到,如果您正确配置了Spring,我尝试使用@Provider注释类:

 <context:component-scan base-package="my.package1 , my.package2">
    <context:include-filter type="annotation" expression="javax.ws.rs.ext.Provider"/>
 </context:component-scan>


但迷雾比我最初想象的要深。。。我更有信心,我在正确的轨道上,只是错过了一步

使用JSR-250的@Resource而不是@Autowired是向前迈出的一大步;它执行@Autowired所需的操作,它是JSR,而不是特定于Spring的


可以很好地用于多种用途。

更好的方法是使用JSR-330注释

与其使用
@Autowired
,不如使用
@Inject
。Spring支持JSR-330注释,并将在幕后使用Autowire实现。对于使用
@Component
@Service
注释的SpringBean,只需将注释替换为JSR-330特定的
@Named

如果您使用的是maven,只需在
pom.xml
文件中包含以下内容

<dependency>
    <groupId>javax.inject</groupId>
    <artifactId>javax.inject</artifactId>
    <version>1</version>
</dependency>

javax.inject
javax.inject
1.