Skip to main content
Jump to: navigation, search


< Jetty‎ | Howto
Revision as of 17:11, 18 August 2010 by (Talk | contribs)


Jetty can be assembled and configured in code or with almost any IoC style framework including Spring. The jetty-spring module is included in jetty@codehaus with some convenience classes and a handy Main method to run Jetty from Spring.


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


The configuration of 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