# Jersey With Spring

## Introduction

This chapter explains how to get started with a simple project that utilizes Jersey with Spring. At the end of this chapter, the reader will be able to configure Jersey inside the Spring framework and take advantage of some Spring specific features available in Jersey. The intended audience of this chapter is developers already familiar with Spring who are interested in using Jersey in their applications.

The easiest way to explain how to use Jersey with Spring is via an example. Rather than creating a Spring application from scratch, we will start with a Web application generated from a Maven archetype and then modify it to run inside Spring.

Should we cite a version of spring here?

## Creating a Web Application

In this section we shall create a simple Web application using one of Jersey's Maven archetypes. Most development environments support Maven and Maven archetypes, but to avoid narrowing this discussion to any specific development envinroment, we shall use command-line tools instead. To create the basic Web application execute the following command:

    mvn archetype:generate -DarchetypeCatalog=http://maven.java.net/

and select the `jersey-quickstart-webapp` option. When prompted choose `example.jersey.spring` for the `groupId` and choose `example-spring-jersey` for the `artifactId`. For all other options choose the default values.

Once the Web application has been generated, it is a good idea to test it to make sure that it is properly configured. For example, using Glassfish listening to port 8080, we can compile and test the application in the `example-spring-jersey` directory as shown below:

    mvn clean install
    asadmin deploy target/example-spring-jersey.war
    curl -v http://localhost:8080/example-spring-jersey/webresources/myresource

If everything works, the last line printed by the `curl` command should be `Hi there!` (if the `curl` command is not available on your system, you can try pointing to the URL using your system's browser).

## Converting a Web Application to Spring

## Scopes

## Sub-Resources

## Injecting Spring Beans

## Spring-based AOP

## Jersey-managed Spring-instantiated resources