Skip to main content
Jump to: navigation, search


< Jetty‎ | Howto


Jetty 7 and Jetty 8 are now EOL (End of Life)

All development and stable releases are being performed with Jetty 9.
This wiki is now officially out of date and all content has been moved to the Jetty Documentation Hub

Direct Link to updated documentation:

You can assemble and configure Jetty in code or with almost any IoC style framework including Spring.

Downloading the Jetty-Spring module

The jetty-spring module is included in jetty-hightide, available at Codehaus, and also as a Maven artifact. This example illustrates a Maven download:

wget --user-agent=other
tar xfz jetty-hightide-7.4.0.v20110414.tar.gz


As distributed, the jetty-hightide bundle does not include the spring dependencies:

  • spring-1.2.8.jar
  • commons-logging-1.0.4.jar

You should download and install these dependencies in $JETTY_HOME/lib/spring

cd lib/spring
wget --user-agent=other
wget --user-agent=other
cd ../..

Using Spring to Configure Jetty

Configuring Jetty via Spring is simply a matter of calling the API as Spring beans. The following is the default jetty-spring.xml file:

  <bean id="contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>
  <bean id="Server" class="org.mortbay.jetty.spring.Server" init-method="start" destroy-method="stop">
    <property name="threadPool">  
      <bean id="ThreadPool" class="org.eclipse.jetty.util.thread.QueuedThreadPool">
        <property name="minThreads" value="10"/>
        <property name="maxThreads" value="50"/>
    <property name="connectors">
        <bean id="Connector" class="org.eclipse.jetty.server.nio.SelectChannelConnector">
          <property name="port" value="8080"/>
    <property name="handler">
      <bean id="handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
        <property name="handlers">
	     <ref bean="contexts"/>
             <bean id="defaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
    <property name="beans">
        <bean id="ContextDeployer" class="org.mortbay.jetty.spring.ContextDeployer">
          <property name="contexts" ref="contexts"/>
          <property name="contextsDir" value="contexts"/>
          <property name="scanInterval" value="5"/>
        <bean id="WebAppDeployer" class="org.eclipse.jetty.deploy.WebAppDeployer">
          <property name="contexts" ref="contexts"/>
          <property name="webAppDir" value="webapps"/>
          <property name="extract" value="true"/>
          <property name="defaultsDescriptor" value="etc/webdefault.xml"/>
        <bean class="">
          <property name="name" value="Test Realm"/>
          <property name="config" value="etc/"/>
          <property name="refreshInterval" value="0"/>

Running Jetty with Spring

There are many ways to launch Spring, including the Jetty start.jar mechanism. The following command line starts the Jetty Spring config file including with the jetty-hightide distribution from codehaus:

  java -jar start.jar OPTIONS=Server,All,spring \
    start.class=org.mortbay.jetty.spring.Main \

This uses the jetty-spring Main class to load the Spring configuration file and join the resulting server.

Back to the top