Jetty实战之 嵌入式Jetty集成Spring运行?转载链接:http://blog.csdn.net/kongxx/article/details/72271071
Jetty实战之 嵌入式Jetty集成Spring运行
?
转载链接:http://blog.csdn.net/kongxx/article/details/7227107
1. 首先修改pom.xml文件,添加spring的依赖项
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.google.code.garbagecan.jettystudy</groupId>
<artifactId>jettystudy</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>jettystudy</name>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<inherited>true</inherited>
<configuration>
<source>1.6</source>
<target>1.6</target>
<debug>true</debug>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty.aggregate</groupId>
<artifactId>jetty-all</artifactId>
<version>8.0.4.v20111024</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.6</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
?2. 创建一个Server类,用来通过spring来启动Jetty server
?4. 创建一个spring配置文件,并放在com/google/code/garbagecan/jettystudy/sample4/spring.xml位置,内容如下.
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="Server" init-method="start" destroy-method="stop">
<property name="connectors">
<list>
<bean id="Connector" value="8080" />
</bean>
</list>
</property>
<property name="handler">
<bean id="handlers" />
<bean />
</list>
</property>
</bean>
</property>
</bean>
</beans> ?其中定义了Jetty Server的配置,包括Connector和Handler等等。
5. 运行MyServer类,然后通过http://localhost:8080/来访问。