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 |
If you are working with Jersey GlassFish update center module installed into your existing GlassFish instance, you will need to follow instructions at the module README file in order to deploy the example.
Otherwise, you can run the example using embedded GlassFish as follows:
run
mvn clean package embedded-glassfish:run
or you can run the example using Jetty as follows:
mvn clean package jetty: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