Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Jetty/Howto/Spring

< Jetty‎ | Howto
Revision as of 14:11, 17 August 2010 by Boulay.intalio.com (Talk | contribs)



Introduction

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.

Dependencies

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

Configuration

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:

<beans>
 
  <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"/>
      </bean>
    </property>
 
    <property name="connectors">
      <list>
        <bean id="Connector" class="org.eclipse.jetty.server.nio.SelectChannelConnector">
          <property name="port" value="8080"/>
        </bean>
      </list>
    </property>
 
    <property name="handler">
      <bean id="handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
        <property name="handlers">
          <list>
	     <ref bean="contexts"/>
             <bean id="defaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
          </list>
        </property>
      </bean>
    </property>
 
    <property name="beans">
      <list>
        <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>
 
        <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>
 
        <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"/>
        </bean>
 
      </list>
    </property>
 
  </bean>
 
</beans>

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 \
    etc/jetty-spring.xml

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

Back to the top