Author: kwin
Date: Sun Nov 27 11:47:16 2016
New Revision: 1771567
URL: http://svn.apache.org/viewvc?rev=1771567&view=rev
Log:
SLING-6249 update documentation with examples how to use OSGi DS annotations
Modified:
sling/site/trunk/content/documentation/the-sling-engine/servlets.mdtext
Modified:
sling/site/trunk/content/documentation/the-sling-engine/servlets.mdtext
URL:
http://svn.apache.org/viewvc/sling/site/trunk/content/documentation/the-sling-engine/servlets.mdtext?rev=1771567&r1=1771566&r2=1771567&view=diff
==============================================================================
--- sling/site/trunk/content/documentation/the-sling-engine/servlets.mdtext
(original)
+++ sling/site/trunk/content/documentation/the-sling-engine/servlets.mdtext Sun
Nov 27 11:47:16 2016
@@ -28,19 +28,23 @@ If `sling.servlet.methods` is not specif
#### Registering a Servlet using Java Annotations
-If you are working with the default Apache Sling development stack you can use
Java Annotations from [Apache Felix Maven SCR
Plugin](http://felix.apache.org/documentation/subprojects/apache-felix-maven-scr-plugin.html)
to register your Sling
-servlets and describe their binding details.
+If you are working with the default Apache Sling development stack you can
either use
+* [OSGi DS
annotations](https://osgi.org/javadoc/r6/cmpn/org/osgi/service/component/annotations/package-summary.html)
(introduced with DS 1.2/OSGi 5, properly supported since [bnd
3.0](https://github.com/bndtools/bndtools/wiki/Changes-in-3.0.0), being used in
[maven-bundle-plugin
3.0.0](http://felix.apache.org/documentation/subprojects/apache-felix-maven-bundle-plugin-bnd.html))
or
+* Generic Felix SCR or Sling-specific `@SlingServlet` annotations from [Apache
Felix Maven SCR
Plugin](http://felix.apache.org/documentation/subprojects/apache-felix-maven-scr-plugin.html)
to register your Sling servlets:
-There are two ways of doing this, either with a Sling-specific @SlingServlet
annotation or with the more generic maven-scr-plugin annotations:
-1. The `@SlingServlet` annotation
+1. OSGi DS annotations (recommended)
:::java
- @SlingServlet(
- resourceTypes = "sling/servlet/default",
- selectors = "hello",
- extensions = "html",
- methods = "GET")
+ @Component(
+ service = { Servlet.class },
+ property = {
+ SLING_SERVLET_RESOURCE_TYPES + "=/apps/my/type"
+ SLING_SERVLET_METHODS + "=GET",
+ SLING_SERVLET_EXTENSIONS + "=html",
+ SLING_SERVLET_SELECTORS + "=hello",
+ }
+ )
public class MyServlet extends SlingSafeMethodsServlet {
@Override
@@ -49,17 +53,16 @@ There are two ways of doing this, either
}
}
-2. The `@Properties` and `@Property` annotations
+Custom OSGi DS annotations (e.g. for Sling servlets) are not yet supported by
the OSGi spec (and therefore by bnd), but this is supposed to be fixed with DS
1.4 (OSGi 7), see also
[FELIX-5396](https://issues.apache.org/jira/browse/FELIX-5396)).
+
+2. The `@SlingServlet` annotation (evaluated by maven-scr-plugin)
:::java
- @Component(metatype = true)
- @Service(Servlet.class)
- @Properties({
- @Property(name = "sling.servlet.resourceTypes", value =
"sling/servlet/default"),
- @Property(name = "sling.servlet.selectors", value = "hello"),
- @Property(name = "sling.servlet.extensions", value = "html"),
- @Property(name = "sling.servlet.methods", value = "GET")
- })
+ @SlingServlet(
+ resourceTypes = "/apps/my/type",
+ selectors = "hello",
+ extensions = "html",
+ methods = "GET")
public class MyServlet extends SlingSafeMethodsServlet {
@Override