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.
Difference between revisions of "Jetty/Howto/Spring"
m |
m |
||
Line 1: | Line 1: | ||
{{Jetty Howto | {{Jetty Howto | ||
|introduction= | |introduction= | ||
− | Jetty can be assembled and configured in code or with almost any IoC style framework including | + | 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 == | == Dependencies == | ||
Line 7: | Line 7: | ||
* spring-1.2.8.jar | * spring-1.2.8.jar | ||
* commons-logging-1.0.4.jar | * commons-logging-1.0.4.jar | ||
− | + | You should download and install these dependencies in $JETTY_HOME/lib/spring | |
== Configuration == | == Configuration == | ||
− | The configuration of Jetty via | + | 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: |
<source lang="xml"> | <source lang="xml"> | ||
<beans> | <beans> | ||
Line 74: | Line 74: | ||
== Running Jetty with Spring == | == Running Jetty with Spring == | ||
− | There are many ways to launch | + | There are many ways to launch Spring, including the Jetty [[Jetty/Feature/Start.jar|start.jar]] mechanism. The following command line starts the Jetty Spring config file including with the jetty-hightide distribution from codehaus: |
<source lang="bash"> | <source lang="bash"> | ||
java -jar start.jar OPTIONS=Server,All,spring \ | java -jar start.jar OPTIONS=Server,All,spring \ | ||
Line 81: | Line 81: | ||
</source> | </source> | ||
− | This uses the [http://svn.codehaus.org/jetty/jetty/trunk/jetty-spring/src/main/java/org/mortbay/jetty/spring/Main.java jetty-spring Main] class to load the | + | This uses the [http://svn.codehaus.org/jetty/jetty/trunk/jetty-spring/src/main/java/org/mortbay/jetty/spring/Main.java jetty-spring Main] class to load the Spring configuration file and join the resulting server. |
}} | }} |
Revision as of 17:11, 18 August 2010
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
You should download and install these dependencies 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.