Spring Jetty 통합
2009/06/05 16:08
Jetty는 Jetty Embeding에서 포스팅한 것 처럼 프로그램에 임베딩이 가능한 Web Server/라이브러리이다.
요즘 Spring에 맛을 들인 후 여기저기 뒤적뒤적 하고 있는데... Spring과 Jetty를 통합하는 예제를 우연찮게 발견했다.
Christopher J. Stehno라는 분의 포스팅을 보면 매우 쉽고 간결하게 통합할 수 있는 예제가 있다. Spring의 위력을 절감하게 되는 부분이다.
- Spring 설정
- Main Class
여기서 설정 몇가지만 변경해 주면... 웹서버가 만들어진다.
기존에 만들었던 Embed된 소스에 즉시 적용해 봐야겠다.
요즘 Spring에 맛을 들인 후 여기저기 뒤적뒤적 하고 있는데... Spring과 Jetty를 통합하는 예제를 우연찮게 발견했다.
Christopher J. Stehno라는 분의 포스팅을 보면 매우 쉽고 간결하게 통합할 수 있는 예제가 있다. Spring의 위력을 절감하게 되는 부분이다.
- Spring 설정
<?xml version="1.0" encoding="UTF-8"?>
<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.xsd">
<bean id="server.Server" class="org.mortbay.jetty.Server" destroy-method="stop">
<property name="threadPool">
<bean class="org.mortbay.thread.QueuedThreadPool">
<property name="maxThreads" value="100" />
</bean>
</property>
<property name="connectors">
<list>
<bean class="org.mortbay.jetty.nio.SelectChannelConnector">
<property name="port" value="8080" />
<property name="maxIdleTime" value="30000" />
</bean>
</list>
</property>
<property name="handler">
<bean class="org.mortbay.jetty.handler.HandlerCollection">
<property name="handlers">
<list>
<ref local="server.ContextHandlerCollection" />
<bean class="org.mortbay.jetty.handler.DefaultHandler" />
<bean class="org.mortbay.jetty.handler.RequestLogHandler">
<property name="requestLog">
<bean class="org.mortbay.jetty.NCSARequestLog">
<constructor-arg value="cfg/logs/jetty-yyyy_mm_dd.log" />
<property name="extended" value="false"/>
</bean>
</property>
</bean>
</list>
</property>
</bean>
</property>
<property name="userRealms">
<list>
<bean class="org.mortbay.jetty.security.HashUserRealm">
<property name="name" value="Test Realm" />
<property name="config" value="cfg/etc/realm.properties" />
</bean>
</list>
</property>
<property name="stopAtShutdown" value="true" />
<property name="sendServerVersion" value="true"/>
</bean>
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject" ref="server.Server" />
<property name="targetMethod" value="addLifeCycle" />
<property name="arguments">
<list><ref local="server.ContextDeployer" /></list>
</property>
</bean>
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject" ref="server.Server" />
<property name="targetMethod" value="addLifeCycle" />
<property name="arguments">
<list><ref local="server.WebAppDeployer" /></list>
</property>
</bean>
<bean id="server.ContextHandlerCollection" class="org.mortbay.jetty.handler.ContextHandlerCollection" />
<bean id="server.ContextDeployer" class="org.mortbay.jetty.deployer.ContextDeployer">
<property name="contexts" ref="server.ContextHandlerCollection" />
<property name="configurationDir">
<bean class="org.mortbay.resource.FileResource">
<constructor-arg value="file://./cfg/contexts" />
</bean>
</property>
<property name="scanInterval" value="1" />
</bean>
<bean id="server.WebAppDeployer" class="org.mortbay.jetty.deployer.WebAppDeployer">
<property name="contexts" ref="server.ContextHandlerCollection" />
<property name="webAppDir" value="cfg/webapps" />
<property name="parentLoaderPriority" value="false" />
<property name="extract" value="true" />
<property name="allowDuplicates" value="false" />
<property name="defaultsDescriptor" value="cfg/etc/webdefault.xml" />
</bean>
</beans>
<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.xsd">
<bean id="server.Server" class="org.mortbay.jetty.Server" destroy-method="stop">
<property name="threadPool">
<bean class="org.mortbay.thread.QueuedThreadPool">
<property name="maxThreads" value="100" />
</bean>
</property>
<property name="connectors">
<list>
<bean class="org.mortbay.jetty.nio.SelectChannelConnector">
<property name="port" value="8080" />
<property name="maxIdleTime" value="30000" />
</bean>
</list>
</property>
<property name="handler">
<bean class="org.mortbay.jetty.handler.HandlerCollection">
<property name="handlers">
<list>
<ref local="server.ContextHandlerCollection" />
<bean class="org.mortbay.jetty.handler.DefaultHandler" />
<bean class="org.mortbay.jetty.handler.RequestLogHandler">
<property name="requestLog">
<bean class="org.mortbay.jetty.NCSARequestLog">
<constructor-arg value="cfg/logs/jetty-yyyy_mm_dd.log" />
<property name="extended" value="false"/>
</bean>
</property>
</bean>
</list>
</property>
</bean>
</property>
<property name="userRealms">
<list>
<bean class="org.mortbay.jetty.security.HashUserRealm">
<property name="name" value="Test Realm" />
<property name="config" value="cfg/etc/realm.properties" />
</bean>
</list>
</property>
<property name="stopAtShutdown" value="true" />
<property name="sendServerVersion" value="true"/>
</bean>
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject" ref="server.Server" />
<property name="targetMethod" value="addLifeCycle" />
<property name="arguments">
<list><ref local="server.ContextDeployer" /></list>
</property>
</bean>
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject" ref="server.Server" />
<property name="targetMethod" value="addLifeCycle" />
<property name="arguments">
<list><ref local="server.WebAppDeployer" /></list>
</property>
</bean>
<bean id="server.ContextHandlerCollection" class="org.mortbay.jetty.handler.ContextHandlerCollection" />
<bean id="server.ContextDeployer" class="org.mortbay.jetty.deployer.ContextDeployer">
<property name="contexts" ref="server.ContextHandlerCollection" />
<property name="configurationDir">
<bean class="org.mortbay.resource.FileResource">
<constructor-arg value="file://./cfg/contexts" />
</bean>
</property>
<property name="scanInterval" value="1" />
</bean>
<bean id="server.WebAppDeployer" class="org.mortbay.jetty.deployer.WebAppDeployer">
<property name="contexts" ref="server.ContextHandlerCollection" />
<property name="webAppDir" value="cfg/webapps" />
<property name="parentLoaderPriority" value="false" />
<property name="extract" value="true" />
<property name="allowDuplicates" value="false" />
<property name="defaultsDescriptor" value="cfg/etc/webdefault.xml" />
</bean>
</beans>
- Main Class
public class Main {
public static void main(String[] args) throws Exception {
ApplicationContext context = new FileSystemXmlApplicationContext("cfg/server-context.xml");
Server server = (Server)context.getBean("server.Server");
server.start();
server.join();
}
}
public static void main(String[] args) throws Exception {
ApplicationContext context = new FileSystemXmlApplicationContext("cfg/server-context.xml");
Server server = (Server)context.getBean("server.Server");
server.start();
server.join();
}
}
여기서 설정 몇가지만 변경해 주면... 웹서버가 만들어진다.
기존에 만들었던 Embed된 소스에 즉시 적용해 봐야겠다.
'Java' 카테고리의 다른 글
| Spring Jetty 통합 (0) | 2009/06/05 |
|---|---|
| Core Spring - Spring Framework Training in SEOUL (0) | 2009/01/29 |
| Velocity 1.6 정식 버전 Release되었네. (0) | 2008/12/03 |
| Velocity 1.6 Beta1이 발표 되었네. (0) | 2008/09/26 |
| IIS와 Tomcat 연동 (0) | 2008/07/29 |
| Jetty Embeding (0) | 2008/06/24 |


이올린에 북마크하기
이올린에 추천하기

