Débora
Débora

Reputation: 5952

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
<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? What if Spring 4 DI is used independently ?

Also please let me know any step by step learning source to integration Spring DI with Jersey ?

Upvotes: 1

Views: 10216

Answers (2)

francis
francis

Reputation: 11

You should add jersey-spring3.jar first like the document in jersey website. 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.

Find ServletContainer.class and set a breakpoint in init() function, as this you can find this step by step.

Upvotes: -2

Ricardo Veguilla
Ricardo Veguilla

Reputation: 3155

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.

From Jersey - Spring DI:

Jersey provides an extension to support Spring DI. This enables Jersey to use Spring beans as JAX-RS components (e.g. resources and providers) and also allows Spring to inject into Jersey managed components.

...

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.

So if you want to use Jersey with Spring you need jersey-spring3 and all the Spring dependencies you normally use.

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.

Upvotes: 5

Related Questions