[英]Jersey with Spring 4 Dependency Injection
I am to use Dependency Injection of Spring framework version 4. I have seen that the Jersey has its DI with plugin 我将使用Spring框架版本4的依赖注入。我已经看到Jersey有插件的DI
<dependency> <groupId>org.glassfish.jersey.ext</groupId> <artifactId>jersey-spring3</artifactId> <version>2.12</version> </dependency>
Is Jersey's DI of Spring recommended or is there special reason to use it? 泽西岛的DI春季推荐还是有特殊原因使用它? What if Spring 4 DI is used independently ?
如果Spring 4 DI独立使用怎么办?
Also please let me know any step by step learning source to integration Spring DI with Jersey ? 另外请让我知道任何一步一步的学习资源来整合Spring DI和Jersey?
The jersey-spring3
extension is not a stand-alone Dependency Injection feature, it's just an extension which makes Jersey aware of Spring's managed beans. jersey-spring3
扩展不是一个独立的依赖注入功能,它只是让Jersey知道Spring的托管bean的扩展。
From Jersey - Spring DI : 来自Jersey - Spring DI :
Jersey provides an extension to support Spring DI.
Jersey提供了支持Spring DI的扩展。 This enables Jersey to use Spring beans as JAX-RS components (eg resources and providers) and also allows Spring to inject into Jersey managed components.
这使Jersey能够将Spring bean用作JAX-RS组件(例如资源和提供程序),并允许Spring注入Jersey托管组件。
...
...
The above module does not add any transitive dependency to Spring modules, so you will need to add Spring 3 dependencies explicitly into your dependency list.
上面的模块没有向Spring模块添加任何传递依赖,因此您需要将Spring 3依赖项显式添加到依赖项列表中。
So if you want to use Jersey with Spring you need jersey-spring3
and all the Spring dependencies you normally use. 因此,如果你想使用Jersey和Spring,你需要
jersey-spring3
和你通常使用的所有Spring依赖项。
By the way, the jersey-spring3
extension is compiled against Spring 3, but should work with Spring 4. See Using Jersey-spring with Spring 4.0 for reference. 顺便说一句,
jersey-spring3
扩展是针对Spring 3编译的,但是应该适用于Spring 4.请参阅使用Jersey-spring和Spring 4.0作为参考。
You should add jersey-spring3.jar
first like the document in jersey website. 您应该首先添加
jersey-spring3.jar
就像在泽西网站上的文档一样。 For this step by step learning source to integration Spring DI with Jersey
, you can do like this when you start up you application debug the application. 对于这个
step by step learning source to integration Spring DI with Jersey
,你可以在启动应用程序调试应用程序时这样做。
Find ServletContainer.class
and set a breakpoint
in init()
function, as this you can find this step by step. 找到
ServletContainer.class
并在init()
函数中设置breakpoint
,这样你就可以逐步找到它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.