Skip to content

Instantly share code, notes, and snippets.

@rponte
Last active September 24, 2015 16:08
Show Gist options
  • Save rponte/773961 to your computer and use it in GitHub Desktop.
Save rponte/773961 to your computer and use it in GitHub Desktop.
Embedded Jetty with Spring 3.x
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:annotation-config />
<context:component-scan base-package="base" />
<bean id="Server" class="org.mortbay.jetty.Server"
init-method="start"
destroy-method="stop">
<property name="connectors">
<list>
<!--<bean id="Connector" class="org.mortbay.jetty.nio.SelectChannelConnector">
<property name="port" value="8080" />
<property name="maxIdleTime" value="30000" />
</bean>-->
<bean id="Connector"
class="org.mortbay.jetty.nio.SelectChannelConnector"
p:port="8181"
p:maxIdleTime="30000"
p:acceptors="10"
p:confidentialPort="8443" />
</list>
</property>
<property name="handler">
<bean id="handlers" class="org.mortbay.jetty.handler.HandlerCollection">
<property name="handlers">
<list>
<bean id="contexts" class="org.mortbay.jetty.handler.ContextHandlerCollection">
<property name="handlers">
<list>
<bean factory-bean="webAppContextFactory" factory-method="createWebAppContext"></bean>
<!-- bean class="org.mortbay.jetty.webapp.WebAppContext">
<property name="contextPath" value="/SysPDVWeb3" />
<property name="war" ref="webAppDir"/>
</bean -->
</list>
</property>
</bean>
</list>
</property>
</bean>
</property>
</bean>
package base;
import java.io.File;
import java.io.IOException;
import java.net.ServerSocket;
import org.mortbay.jetty.webapp.WebAppContext;
import org.springframework.stereotype.Component;
import br.com.syspdv.initializers.DefineHomeInitializer;
@Component
public class WebAppContextFactory {
public static final String SYSPDVWEB_CTX = "/SysPDVWeb";
public WebAppContext createWebAppContext() {
String webApp = getWebAppDir();
WebAppContext ctx = new WebAppContext(webApp, SYSPDVWEB_CTX);
ctx.setParentLoaderPriority(true);
return ctx;
}
public String getWebAppDir() {
return new File("WebRoot").getAbsolutePath();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment