Java Spring and Resteasy Configuration

I am trying to integrate Resteasy and Spring; I followed both documents for Resteasy and this post: Inject Spring beans in RestEasy . I have work using @Autowire or other Spring annotations in the rest class, but I would like to do this by keeping my rest classes free of Spring (or DI) dependencies. I would also like to configure Spring only through java configuration. In the Spring configuration, I added the following:

<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>

and of course I have in web.xml, so Spring config is selected by SpringContextLoaderListener:

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

Removing @Autowire annotations, if I also remove the first package (where I configured the injections via Spring java config), the injection does not occur, and the fields remain empty; if I remove the second package, the URLs for the rest of the classes are not recognized with resteasy.

I would like to configure injections only in the Spring configuration, is there a way for resteasy to recognize paths from Spring beans that are configured externally?

EDIT: I noticed that what I'm trying to do works with annotated @Provider classes, given that you configured Spring correctly:

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

But the mystery is deeper than I thought at first ... I'm sure I'm on the right track and just missed a step!

+3
source share
2 answers

JSR-250 @Resource @Autowired - ; , @Autowired, JSR, Spring.

.

0

- JSR-330.

@Autowired, @Inject. Spring JSR-330 Autowire . Spring beans, @Component, @Service, @Named JSR-330.

maven, pom.xml .

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

All Articles