# Spring Annotations Example

This example demonstrates how to use spring and spring annotations, which requires spring >= 2.5. Included is an example that shows how to use spring-aop with jersey - use spring-aop as you're used to it with your spring bean (spring managed resource class).

There's also an example resource (`JerseyAutowiredResource`) that shows how to use annotation based autowiring with spring < 2.5 (via the `@Autowire` annotation provided by jersey-spring.

## Contents

The example consists of four resource classes:

`com.sun.jersey.samples.springannotations.resources.SpringResourcedResource`
  A resource class that demonstrates the usage of the @Resource annotation provided/supported since spring-2.5+.
`com.sun.jersey.samples.springannotations.resources.SpringAutowiredResource`
  A resource class that demonstrates the usage of the @Autowired annotation provided by spring-2.5+.
`com.sun.jersey.samples.springannotations.resources.aop.SpringAopResource`
  A resource class that demonstrates the usage of spring-aop. The resource method (of the spring managed resource class) is annotated with a custom `@Secure` annotation. A `SecurityAdvice` is defined with a pointcut matching methods with this annotation (this dummy advice just logs to stdout). The resource class must be managed by spring so that spring-aop can come into play.
  The resource class also has a subresource locator that obtains the subresource instance from the `ResourceContext`, so that this subresource instance is also created and proxied by spring.
`com.sun.jersey.samples.springannotations.resources.jerseymanaged.JerseyAutowiredResource`
  A resource class that demonstrates the usage of the @Autowire annotation provided by jersey-spring (for users of spring < 2.5).

The mapping of the URI path space is presented in the following table:

URI path | Resource class | HTTP methods
--- | --- | ---
/spring-resourced | SpringResourcedResource | GET
/spring-autowired | SpringAutowiredResource | GET
/spring-aop | SpringAopResource | GET
/spring-aop/subresource | SpringAopSubResource | GET
/jersey-autowired | JerseyAutowiredResource | GET

## Running the Example

Run the example as follows:

run

> `mvn glassfish:run`

From a web browser, visit:

> `http://localhost:8080/spring/spring-resourced`
> `http://localhost:8080/spring/spring-autowired`
> `http://localhost:8080/spring/spring-aop`
> `http://localhost:8080/spring/spring-aop/subresource`
> `http://localhost:8080/spring/jersey-autowired`