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.
The example consists of four resource classes:
com.sun.jersey.samples.springannotations.resources.SpringResourcedResource
com.sun.jersey.samples.springannotations.resources.SpringAutowiredResource
com.sun.jersey.samples.springannotations.resources.aop.SpringAopResource
@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.ResourceContext
, so that this subresource instance is also created and proxied by spring.com.sun.jersey.samples.springannotations.resources.jerseymanaged.JerseyAutowiredResource
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 |
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