I am using Jersey 2.10 and jersey-spring3 and Spring 4. I want to achieve DI(basically services) in jersey resources as well as in other places and want to create Spring Bea
web-app:
contextClass
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
contextConfigLocation
xxx.xxx.configuration.ApplicationConfiguration
org.springframework.web.context.ContextLoaderListener
SpringApplication
org.glassfish.jersey.servlet.ServletContainer
jersey.config.server.provider.classnames
xxx.xxx.controllers.HelloController
1
SpringApplication
/*
JavaBased Configuration:
@Configuration
public class ApplicationConfiguration {
@Bean
HelloService helloService () {
return new HelloServiceImpl();
}
}
and simple controller:
@Component
@Path("/helloController")
public class HelloController {
@Autowired
@Qualifier("helloService")
private HelloService helloService ;
@GET
@Path("/hello")
public String hello() {
helloService.service();
}
}
for testing:
localhost:8080/[AppName]/helloController/hello
remember about excluding old Spring dependencies you may have some conflicts if you don't. You can do this same as on the example below or through DependencyManagement.
org.glassfish.jersey.ext
jersey-spring3
2.11
spring-context
org.springframework
spring-beans
org.springframework
spring-core
org.springframework
spring-web
org.springframework
jersey-server
org.glassfish.jersey.core
jersey-container-servlet-core
org.glassfish.jersey.containers
hk2
org.glassfish.hk2
org.springframework
spring-core
4.0.6.RELEASE
org.springframework
spring-context
4.0.6.RELEASE
org.springframework
spring-beans
4.0.6.RELEASE
org.springframework
spring-web
4.0.6.RELEASE
org.springframework
spring-aspects
4.0.6.RELEASE