Jetty Logo
Version: 9.2.2-SNAPSHOT
Contact the core Jetty developers at www.webtide.com

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

Chapter 12. Annotations

Table of Contents

Quick Setup
Working with Annotations
Using Annotations with Jetty Embedded

Jetty supports the servlet specification annotations. It is not enabled by default, so the following sections show you how to enable it, and how to use them.

Quick Setup

If you are using the standard distribution of Jetty, and want to enable processing of annotation for all your webapps, edit the $JETTY_HOME/start.ini file and uncomment the following lines:

If you want to use annotations that relate to JNDI, such as @Resource and @Resources then you should also uncomment these other lines also:

You can now start Jetty and use annotations within your webapps. See Using Annotations for more information.

Since jetty-9.1.0 annotation scanning will be conducted by default in a multi-threaded manner. This speeds up the process of opening jar files and looking for discoverable annotations. Jetty will use threads from the configured thread pool to perform the scanning. You can disable threaded scanning and use just the single main execution thread if for some reason you need to. You have several options for doing this:

  1. Set org.eclipse.jetty.annotations.multiThreaded to false on a context attribute for the specific webapp you want to affect

  2. Set org.eclipse.jetty.annotations.multiThreaded to false on a Server attribute to affect all webapps deployed into that Server???

  3. Set -Dorg.eclipse.jetty.annotations.multiThreaded=false as a System property in a start.ini file or command line to affect all webapps in the jvm

By default, Jetty will wait up to 60 seconds for the scanning to complete when using the multi-threaded mode. If you would like to make it longer or shorter, you can use any of the following:

  1. Set org.eclipse.jetty.annotations.maxWait as a context attribute to the time in seconds you want to maximally wait for scanning to complete. This affects the specific webapp only.

  2. Set org.eclipse.jetty.annotations.maxWait as a Server attribute to the time in secods you want to maximally wait for scanning to complete. This affects all webapps deployed to that Server.

  3. Set -Dorg.eclipse.jetty.annotations.maxWait as a System property to the time in seconds you want to maximally wait for scanning to complete. This affects all webapps deployed in the jvm.

See an error or something missing? Contribute to this documentation at Github!(Generated: 2014-07-23T01:00:31-07:00)