| 1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| 2 |
<!-- |
| 3 |
|
| 4 |
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
| 5 |
|
| 6 |
Copyright (c) 2010-2012 Oracle and/or its affiliates. All rights reserved. |
| 7 |
|
| 8 |
The contents of this file are subject to the terms of either the GNU |
| 9 |
General Public License Version 2 only ("GPL") or the Common Development |
| 10 |
and Distribution License("CDDL") (collectively, the "License"). You |
| 11 |
may not use this file except in compliance with the License. You can |
| 12 |
obtain a copy of the License at |
| 13 |
http://glassfish.java.net/public/CDDL+GPL_1_1.html |
| 14 |
or packager/legal/LICENSE.txt. See the License for the specific |
| 15 |
language governing permissions and limitations under the License. |
| 16 |
|
| 17 |
When distributing the software, include this License Header Notice in each |
| 18 |
file and include the License file at packager/legal/LICENSE.txt. |
| 19 |
|
| 20 |
GPL Classpath Exception: |
| 21 |
Oracle designates this particular file as subject to the "Classpath" |
| 22 |
exception as provided by Oracle in the GPL Version 2 section of the License |
| 23 |
file that accompanied this code. |
| 24 |
|
| 25 |
Modifications: |
| 26 |
If applicable, add the following below the License Header, with the fields |
| 27 |
enclosed by brackets [] replaced by your own identifying information: |
| 28 |
"Portions Copyright [year] [name of copyright owner]" |
| 29 |
|
| 30 |
Contributor(s): |
| 31 |
If you wish your version of this file to be governed by only the CDDL or |
| 32 |
only the GPL Version 2, indicate your decision by adding "[Contributor] |
| 33 |
elects to include this software in this distribution under the [CDDL or GPL |
| 34 |
Version 2] license." If you don't indicate a single choice of license, a |
| 35 |
recipient has the option to distribute your version of this file under |
| 36 |
either the CDDL, the GPL Version 2 or to extend the choice of license to |
| 37 |
its licensees as provided above. However, if you add GPL Version 2 code |
| 38 |
and therefore, elected the GPL Version 2 license, then the option applies |
| 39 |
only if the new code is made subject to such option by the copyright |
| 40 |
holder. |
| 41 |
|
| 42 |
--> |
| 43 |
<html><head><title>Spring Annotations Example</title></head> |
| 44 |
|
| 45 |
|
| 46 |
<body> |
| 47 |
<h1>Spring Annotations Example</h1> |
| 48 |
|
| 49 |
<p>This example demonstrates how to use spring and spring annotations, which requires spring >= 2.5. Included is an example |
| 50 |
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).</p> |
| 51 |
<p>There's also an example resource (<code>JerseyAutowiredResource</code>) that shows how to use annotation based autowiring with spring < 2.5 |
| 52 |
(via the <code>@Autowire</code> annotation provided by jersey-spring). |
| 53 |
</p> |
| 54 |
|
| 55 |
<h2>Contents</h2> |
| 56 |
<p>The example consists of four resource classes:</p> |
| 57 |
<dl> |
| 58 |
|
| 59 |
<dt><code>com.sun.jersey.samples.springannotations.resources.SpringResourcedResource</code></dt> |
| 60 |
<dd>A resource class that demonstrates the usage of the |
| 61 |
<a href="http://java.sun.com/javase/6/docs/api/javax/annotation/Resource.html">@Resource</a> annotation |
| 62 |
provided/supported since spring-2.5+.</dd> |
| 63 |
|
| 64 |
<dt><code>com.sun.jersey.samples.springannotations.resources.SpringAutowiredResource</code></dt> |
| 65 |
<dd>A resource class that demonstrates the usage of the |
| 66 |
<a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/beans/factory/annotation/Autowired.html">@Autowired</a> |
| 67 |
annotation provided by spring-2.5+.</dd> |
| 68 |
|
| 69 |
<dt><code>com.sun.jersey.samples.springannotations.resources.aop.SpringAopResource</code></dt> |
| 70 |
<dd>A resource class that demonstrates the usage of |
| 71 |
<a href="http://static.springframework.org/spring/docs/2.5.x/reference/aop.html">spring-aop</a>. |
| 72 |
The resource method (of the spring managed resource class) is annotated with a custom <code>@Secure</code> |
| 73 |
annotation. A <code>SecurityAdvice</code> is defined with a pointcut matching methods with this |
| 74 |
annotation (this dummy advice just logs to stdout). The resource class <strong>must</strong> be managed by |
| 75 |
spring so that spring-aop can come into play.<br/> |
| 76 |
The resource class also has a subresource locator that obtains the subresource instance from |
| 77 |
the <code>ResourceContext</code>, so that this subresource instance is also created and proxied by spring.</dd> |
| 78 |
|
| 79 |
<dt><code>com.sun.jersey.samples.springannotations.resources.jerseymanaged.JerseyAutowiredResource</code></dt> |
| 80 |
<dd>A resource class that demonstrates the usage of the |
| 81 |
<a href="http://jersey.java.net/nonav/apidocs/latest/contribs/jersey-spring/com/sun/jersey/api/spring/Autowire.html">@Autowire</a> |
| 82 |
annotation provided by jersey-spring (for users of spring < 2.5).</dd> |
| 83 |
|
| 84 |
</dl> |
| 85 |
<p>The mapping of the URI path space is presented in the following table:</p> |
| 86 |
<table border="1"> |
| 87 |
<tr> |
| 88 |
<th>URI path</th> |
| 89 |
<th>Resource class</th> |
| 90 |
<th>HTTP methods</th> |
| 91 |
</tr> |
| 92 |
<tr> |
| 93 |
<td>/spring-resourced</td> |
| 94 |
<td>SpringResourcedResource</td> |
| 95 |
<td>GET</td> |
| 96 |
</tr> |
| 97 |
<tr> |
| 98 |
<td>/spring-autowired</td> |
| 99 |
<td>SpringAutowiredResource</td> |
| 100 |
<td>GET</td> |
| 101 |
</tr> |
| 102 |
<tr> |
| 103 |
<td>/spring-aop</td> |
| 104 |
<td>SpringAopResource</td> |
| 105 |
<td>GET</td> |
| 106 |
</tr> |
| 107 |
<tr> |
| 108 |
<td>/spring-aop/subresource</td> |
| 109 |
<td>SpringAopSubResource</td> |
| 110 |
<td>GET</td> |
| 111 |
</tr> |
| 112 |
<tr> |
| 113 |
<td>/jersey-autowired</td> |
| 114 |
<td>JerseyAutowiredResource</td> |
| 115 |
<td>GET</td> |
| 116 |
</tr> |
| 117 |
</table> |
| 118 |
|
| 119 |
<h2>Running the Example</h2> |
| 120 |
<p>If you are working with Jersey GlassFish update center module installed into your existing GlassFish instance, |
| 121 |
you will need to follow instructions at <a href="../../README.html">the module README file</a> in order to deploy the example. |
| 122 |
<p>Otherwise, you can run the example using embedded GlassFish as follows:</p> |
| 123 |
<p> run |
| 124 |
<blockquote><code>mvn clean package embedded-glassfish:run</code></blockquote> |
| 125 |
<p>or you can run the example using Jetty as follows:</p> |
| 126 |
<blockquote><code>mvn clean package jetty:run</code></blockquote> |
| 127 |
<p>From a web browser, visit:</p> |
| 128 |
<blockquote> |
| 129 |
<code><a href="http://localhost:8080/spring/spring-resourced">http://localhost:8080/spring/spring-resourced</a></code> |
| 130 |
<br/> |
| 131 |
<code><a href="http://localhost:8080/spring/spring-autowired">http://localhost:8080/spring/spring-autowired</a></code> |
| 132 |
<br/> |
| 133 |
<code><a href="http://localhost:8080/spring/spring-aop">http://localhost:8080/spring/spring-aop</a></code> |
| 134 |
<br/> |
| 135 |
<code><a href="http://localhost:8080/spring/spring-aop/subresource">http://localhost:8080/spring/spring-aop/subresource</a></code> |
| 136 |
<br/> |
| 137 |
<code><a href="http://localhost:8080/spring/jersey-autowired">http://localhost:8080/spring/jersey-autowired</a></code> |
| 138 |
</blockquote> |
| 139 |
</body></html> |