Fab*_*nte 15
泽西岛2.3现在有弹簧支持:
https://jersey.github.io/documentation/latest/user-guide.html#spring
如文档中所述
Spring扩展模块配置基于注释
所以你必须告诉spring扫描你的类路径,例如:
<context:component-scan base-package="my.package.to.resources">
Run Code Online (Sandbox Code Playgroud)
并使用spring注释注释您的资源类(我建议使用@Component,然后指定jersey资源范围@ Singleton/@ PerLookup/@RequestScoped)
@Component
@Singleton
@Path("example")
public class Example {
//Spring beans can't be injected directly into JAX-RS classes by using Spring XML configuration
@Autowired
private MyOtherBean myOtherBean;
@GET @Path("hello")
public String hello() {
return myOtherBean.hello();
}
}
Run Code Online (Sandbox Code Playgroud)
ant*_*tix 11
截至2013年6月,Jersey 2.0没有正式的Spring支持.有两种选择:
也可以看看:
http://jersey.576304.n2.nabble.com/Spring-framework-support-for-Jersey-2-td7580673.html
编辑:泽西岛2.3现在有弹簧支持,请参阅Fabio下面的答案
Jef*_*rey -7
您应该能够对球衣组件进行注释,然后使用注释来注入 Bean。
@Service //(or @Component)
public class MyJerseyService {
@Autowired
private MyObj mySpringBean
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11759 次 |
| 最近记录: |