Jump to: navigation, search


< Jetty‎ | Howto
Revision as of 13:11, 17 August 2010 by Boulay.intalio.com (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

These dependencies should be downloaded and installed 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="org.eclipse.jetty.security.HashLoginService">
          <property name="name" value="Test Realm"/>
          <property name="config" value="etc/realm.properties"/>
          <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.