# 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.

To enable JAX-RS resources to work Spring functionality that requires proxying, such as Spring transaction management (with `@Transactional`), Spring Security and aspect oriented programming (such as `@Aspect`), the resources must themselves be managed by Spring, by annotating with `@Component`, `@Service`, `@Controller` or `@Repository`:

    import javax.ws.rs.GET;
    import javax.ws.rs.Path;
    import org.springframework.stereotype.Component;

    @Component
    @Path("/")
    public class SomeResource {

        @Transactional
        @GET
        public void updateResource() {
            // ...
        }
    }

Limitations:

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

## 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>&version;</version>
    </dependency>

The above module adds transitive dependencies on Spring modules. See &jersey.ext.spring3.deps.link; module dependencies for more details about list and scope of dependencies. Please note the module depends on &hk2.spring-bridge.link; that is used to inject Spring services into HK2 services or inject HK2 services into Spring services.

## 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.

## Example

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