Chapter 22. Spring DI
Prev |  | Next

Links: Table of Contents | Single HTML

## Chapter 22. 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 Spring extension module configuration is based on annotations. Spring beans are injected and JAX-RS classes are made Spring managed using annotations. Injected Spring beans can have further dependencies injected using Spring XML configuration. Spring singleton and request scopes are supported.

Limitations:

- Spring beans can't be injected directly into JAX-RS classes by using Spring XML configuration

## 22.1. Dependencies

If you want to use Jersey Spring DI support you will need to add the jersey-spring3 module into the list of your dependencies:

    <dependency>
        <groupId>org.glassfish.jersey.ext</groupId>
        <artifactId>jersey-spring3</artifactId>
        <version>2.10.1</version>
    </dependency>

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.

## 22.2. Registration and Configuration

To use capabilities of Jersey Spring 3 DI support in your JAX-RS/Jersey application you need to have the above mentioned module on your class-path.

## 22.3. Example

To see an example of Spring DI support in Jersey refer to the Spring DI example.

Prev |  | Next
Chapter 21. Custom Injection and Lifecycle Management | Home | Chapter 23. Jersey Test Framework