blob: be0ccc9476adc7ce995689c8bccd7990d4cf866e [file] [log] [blame]
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Working with Annotations</title><link rel="stylesheet" type="text/css" href="css/docbook.css"><meta name="generator" content="DocBook XSL-NS Stylesheets V1.76.1"><meta name="keywords" content="jetty, servlet-api, cometd, http, spdy, eclipse, maven, java, software"><link rel="home" href="index.html" title="Jetty : The Definitive Reference"><link rel="up" href="annotations.html" title="Chapter&nbsp;13.&nbsp;Annotations"><link rel="prev" href="annotations.html" title="Chapter&nbsp;13.&nbsp;Annotations"><link rel="next" href="using-annotations-embedded.html" title="Using Annotations with Jetty Embedded"><link xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" rel="shortcut icon" href="images/favicon.ico"><script type="text/javascript" src="js/shCore.js"></script><script type="text/javascript" src="js/shBrushJava.js"></script><script type="text/javascript" src="js/shBrushXml.js"></script><script type="text/javascript" src="js/shBrushBash.js"></script><script type="text/javascript" src="js/shBrushJScript.js"></script><script type="text/javascript" src="js/shBrushSql.js"></script><script type="text/javascript" src="js/shBrushProperties.js"></script><script type="text/javascript" src="js/shBrushPlain.js"></script><link type="text/css" rel="stylesheet" href="css/shCore.css"><link type="text/css" rel="stylesheet" href="css/shThemeEclipse.css"><link type="text/css" rel="stylesheet" href="css/font-awesome.min.css"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><tr><td style="width: 25%"><a href="http://www.eclipse.org/jetty"><img src="images/jetty-header-logo.png" alt="Jetty Logo"></a><br><span style="font-size: small">
Version: 9.0.6.v20130930</span></td><td style="width: 50%"><script type="text/javascript"> (function() {
var cx = '016459005284625897022:obd4lsai2ds';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
'//www.google.com/cse/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
})();
</script><gcse:search></gcse:search></td></tr></table><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Working with Annotations</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="annotations.html"><i class="icon-chevron-left"></i> Previous</a>&nbsp;</td><th width="60%" align="center">Chapter&nbsp;13.&nbsp;Annotations<br><a accesskey="p" href="index.html"><i class="icon-home"></i> Home</a></th><td width="20%" align="right">&nbsp;<a accesskey="n" href="using-annotations-embedded.html">Next <i class="icon-chevron-right"></i></a></td></tr></table><hr></div><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="jetty-callout"><h5 class="callout"><a href="http://www.webtide.com/support.jsp">Contact the core Jetty developers at
<span class="website">www.webtide.com</span></a></h5><p>
private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ...
scalability guidance for your apps and Ajax/Comet projects ... development services from 1 day to full product delivery
</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="using-annotations"></a>Working with Annotations</h2></div></div></div><div class="toc"><dl><dt><span class="section"><a href="using-annotations.html#d0e9258">Which Annotations Are Supported</a></span></dt><dt><span class="section"><a href="using-annotations.html#d0e9303">Discovered vs Introspected Annotations</a></span></dt><dt><span class="section"><a href="using-annotations.html#d0e9332">Which Jars Are Examined For Discovered Annotations</a></span></dt></dl></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="d0e9258"></a>Which Annotations Are Supported</h3></div></div></div><p>Jetty supports interpretation and application of the following
annotations:</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>@Resource</p></li><li class="listitem"><p>@Resources</p></li><li class="listitem"><p>@PostConstruct</p></li><li class="listitem"><p>@PreDestroy</p></li><li class="listitem"><p>@DeclaredRoles</p></li><li class="listitem"><p>@RunAs</p></li><li class="listitem"><p>@MultipartConfig</p></li><li class="listitem"><p>@WebServlet</p></li><li class="listitem"><p>@WebFilter</p></li><li class="listitem"><p>@WebListener</p></li><li class="listitem"><p>@WebInitParam</p></li><li class="listitem"><p>@ServletSecurity, @HttpConstraint, @HttpMethodConstraint</p></li><li class="listitem"><p>@HandlesTypes (on ServletContainerInitializers)</p></li></ul></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="d0e9303"></a>Discovered vs Introspected Annotations</h3></div></div></div><p>Some types of annotation can be placed on any classes, not
necessarily just those with which the container interacts directly. We
call these type of annotations "discovered" to indicate that the container
must take proactive action to go out and find them. The other type of
annotation we call "introspected", meaning that they occur on classes with
which the container interacts during their lifecycle (eg
javax.servlet.Servlet, javax.servlet.Filter etc), and hence can be found
by simple inspection of the class at that point. </p><p>Some examples of discovered annotations are:</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>@WebServlet</p></li><li class="listitem"><p>@WebFilter</p></li><li class="listitem"><p>@WebListener</p></li></ul></div><p>Some examples of introspected annotations are:</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>@PostConstruct</p></li><li class="listitem"><p>@PreDestroy</p></li><li class="listitem"><p>@Resource</p></li></ul></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="d0e9332"></a>Which Jars Are Examined For Discovered Annotations</h3></div></div></div><p>The web.xml file can contain the attribute
<code class="code">metadata-complete</code>. If this is set to <code class="code">true</code>, then
<span class="emphasis"><em>no</em></span> scanning of discoverable annotations takes place.
However, scanning of classes may <span class="emphasis"><em>still</em></span> occur because
of <a class="link" href="http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContainerInitializer.html" target="_top">javax.servlet.ServletContainerInitializer</a>s.
Classes implementing this interface are found by Jetty using the <a class="link" href="http://docs.oracle.com/javase/6/docs/api/java/util/ServiceLoader.html" target="_top">javax.util.ServiceLoader</a>
mechanism, and if one is present <span class="emphasis"><em>and</em></span> it includes the
@HandlesTypes annotation, then Jetty must scan the class hierarchy of the
web application. This may be very time-consuming if you have many jars in
the container's path or in the webapp's WEB-INF/lib.</p><p>If scanning is to take place - because either
<code class="code">metadata-complete</code> is <code class="code">false</code> or missing, or
because there are one or more <a class="link" href="http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContainerInitializer.html" target="_top">javax.servlet.ServletContainerIntializer</a>s
with @HandlesTypes - then Jetty must consider both the container's
classpath and the webapp's classpath.</p><p>By default, Jetty will <span class="emphasis"><em>not</em></span> scan any classes
that are on the container's classpath. If you need to cause jars and
classes that are on the container's classpath to be scanned, then you can
use the <a class="link" href="configuring-webapps.html#container-include-jar-pattern" title="org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern">org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern</a>
context attribute to specify a pattern for jars and directories from the
container's classpath to scan.</p><p>By default, Jetty will scan <span class="emphasis"><em>all </em></span>classes from
<code class="code">WEB-INF/classes</code>, and all jars from <code class="code">WEB-INF/lib</code>
according to the order, if any, established by absolute or relative
ordering clauses in web.xml. If your webapp contains many jars, you can
significantly speed up deployment by omitting them from scanning. To do
this, use the <a class="link" href="configuring-webapps.html#web-inf-include-jar-pattern" title="org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern">org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern</a>
context attribute to define the patterns of jars that you specifically
want to be scanned.</p></div></div><script type="text/javascript">
SyntaxHighlighter.all()
</script><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="annotations.html"><i class="icon-chevron-left"></i> Previous</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="annotations.html"><i class="icon-chevron-up"></i> Top</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="using-annotations-embedded.html">Next <i class="icon-chevron-right"></i></a></td></tr><tr><td width="40%" align="left" valign="top">Chapter&nbsp;13.&nbsp;Annotations&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="index.html"><i class="icon-home"></i> Home</a></td><td width="40%" align="right" valign="top">&nbsp;Using Annotations with Jetty Embedded</td></tr></table></div><p xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><div class="jetty-callout">
See an error or something missing?
<span class="callout"><a href="http://github.com/jetty-project/jetty-documentation">Contribute to this documentation at
<span class="website"><i class="icon-github"></i> Github!</span></a></span><span style="float: right"><i>(Generated: 2013-10-30T13:20:27-05:00)</i></span></div></p><script xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-1149868-7']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script></body></html>