Jetty Development Guide: Framework

Source: Internet
Author: User
Spring settings

You can embed jetty into your project, or use almost all IOC frameworks, including spring. If all you want to do is set jetty server in your spring, the following XML snippet can be used as an example. If you want to replace jetty-XML with spring, the rest of the module system cannot be used.

Jetty-spring Module

The framework of a jetty spring module can be activated through the module mechanism. For example:

$ java -jar start.jar --add-to-startd=spring

This (or use the -- add-to-Start = spring command) to create a $ {Jetty. Home}/lib/spring folder and put the jetty-spring integrated jar into it. It does not provide spring jars and their dependencies. You will need to download these and place them to the classpath of jetty-you can use spring. $ {Jetty. home}/lib/spring.

Configure jetty With Spring

Configuring jetty through spring is a problem of calling APIs as spring beans. The following figure shows an example of simulating the default jetty STARTUP configuration:

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <!-- =============================================================== --><!-- Configure the Jetty Server with Spring                          --><!-- This file is the similar to jetty.xml, but written in spring    --><!-- XmlBeanFactory format.                                          --><!-- =============================================================== --> <beans>    <bean id="contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>    <bean id="server" name="Main" class="org.eclipse.jetty.server.Server" init-method="start" destroy-method="stop">        <constructor-arg>            <bean id="threadPool" class="org.eclipse.jetty.util.thread.QueuedThreadPool">                <property name="minThreads" value="10"/>                <property name="maxThreads" value="50"/>            </bean>        </constructor-arg>        <property name="connectors">            <list>                <bean id="connector" class="org.eclipse.jetty.server.ServerConnector">                    <constructor-arg ref="server"/>                    <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="deploymentManager" class="org.eclipse.jetty.deploy.DeploymentManager">                    <property name="contexts" ref="contexts"/>                    <property name="appProviders">                        <list>                            <bean id="webAppProvider" class="org.eclipse.jetty.deploy.providers.WebAppProvider">                                <property name="monitoredDirName" value="webapps"/>                                <property name="scanInterval" value="1"/>                                <property name="extractWars" value="true"/>                            </bean>                        </list>                    </property>                </bean>            </list>        </property>    </bean></beans>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.