java - Jersey 2 + Spring: @Autowired is null - Stack Overflow
Spring managed beans cannot be injected to JAX-RS classes directly, you need to use Jersey extension for integrating it with Spring.
There is a maven dependency which you don't have in your pom.xml
<dependency> <groupId>org.glassfish.jersey.ext</groupId> <artifactId>jersey-spring3</artifactId> <version>2.12</version> </dependency>
Refer to Jersey Documentation: Chapter 22. Spring DI and at the bottom of the page, there is a link to sample spring integration Github project.
Another problem I've seen in your project is you didn't show how spring context should be loaded and configured. You need to configure it in your web.xml
<listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param>
Read full article from java - Jersey 2 + Spring: @Autowired is null - Stack Overflow
No comments:
Post a Comment