fulfil this things and let spring start when the server starts
This commit is contained in:
parent
a368f443a8
commit
75b2537cfc
25
pom.xml
25
pom.xml
|
@ -17,16 +17,6 @@
|
|||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-server</artifactId>
|
||||
<version>8.1.11.v20130520</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-servlet</artifactId>
|
||||
<version>8.1.11.v20130520</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
|
@ -57,11 +47,6 @@
|
|||
<artifactId>maxq</artifactId>
|
||||
<version>0.94</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.httpunit</groupId>
|
||||
<artifactId>httpunit</artifactId>
|
||||
<version>1.7.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
|
@ -120,6 +105,16 @@
|
|||
<artifactId>bench4q-share</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-webapp</artifactId>
|
||||
<version>9.1.0.RC1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-server</artifactId>
|
||||
<version>9.1.0.RC1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<repositories>
|
||||
<repository>
|
||||
|
|
|
@ -1,19 +1,12 @@
|
|||
package org.bench4q.master;
|
||||
|
||||
import org.bench4q.master.service.db.AgentService;
|
||||
import org.bench4q.master.testplan.highavailable.HighAvailablePool;
|
||||
import org.eclipse.jetty.server.Connector;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.bio.SocketConnector;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.springframework.web.servlet.DispatcherServlet;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
|
||||
public class MasterServer {
|
||||
private Server server;
|
||||
private int port;
|
||||
private AgentService agentService;
|
||||
private HighAvailablePool highAvailablePool;
|
||||
|
||||
private Server getServer() {
|
||||
return server;
|
||||
|
@ -35,35 +28,15 @@ public class MasterServer {
|
|||
this.setPort(port);
|
||||
}
|
||||
|
||||
public AgentService getAgentService() {
|
||||
return agentService;
|
||||
}
|
||||
|
||||
public void setAgentService(AgentService agentPoolService) {
|
||||
this.agentService = agentPoolService;
|
||||
}
|
||||
|
||||
public HighAvailablePool getHighAvailablePool() {
|
||||
return highAvailablePool;
|
||||
}
|
||||
|
||||
public void setHighAvailablePool(HighAvailablePool highAvailablePool) {
|
||||
this.highAvailablePool = highAvailablePool;
|
||||
}
|
||||
|
||||
public boolean start() {
|
||||
try {
|
||||
this.setServer(new Server());
|
||||
Connector connector = new SocketConnector();
|
||||
connector.setPort(this.getPort());
|
||||
this.getServer().addConnector(connector);
|
||||
ServletContextHandler servletContextHandler = new ServletContextHandler();
|
||||
ServletHolder servletHolder = servletContextHandler.addServlet(
|
||||
DispatcherServlet.class, "/");
|
||||
servletHolder
|
||||
.setInitParameter("contextConfigLocation",
|
||||
"classpath*:org/bench4q/master/config/application-context.xml");
|
||||
this.getServer().setHandler(servletContextHandler);
|
||||
this.setServer(new Server(this.getPort()));
|
||||
WebAppContext webAppContext = new WebAppContext();
|
||||
webAppContext.setContextPath("/");
|
||||
webAppContext.setResourceBase("src/main/webapp");
|
||||
webAppContext.setDescriptor("src/main/webapp/WEB-INF/web.xml");
|
||||
webAppContext.setConfigurationDiscovered(true);
|
||||
this.getServer().setHandler(webAppContext);
|
||||
this.getServer().start();
|
||||
this.getServer().join();
|
||||
return true;
|
||||
|
@ -76,6 +49,11 @@ public class MasterServer {
|
|||
public boolean stop() {
|
||||
try {
|
||||
if (this.getServer() != null) {
|
||||
for (Connector connector : this.getServer().getConnectors()) {
|
||||
if (connector != null) {
|
||||
connector.shutdown();
|
||||
}
|
||||
}
|
||||
this.getServer().stop();
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
|
||||
version="3.0">
|
||||
<display-name>bench4q-master</display-name>
|
||||
<listener>
|
||||
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
|
||||
</listener>
|
||||
<servlet>
|
||||
<servlet-name>dispatcherServlet</servlet-name>
|
||||
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
|
||||
<init-param>
|
||||
<param-name>contextConfigLocation</param-name>
|
||||
<param-value>
|
||||
/WEB-INF/application*.xml
|
||||
</param-value>
|
||||
</init-param>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>dispatcherServlet</servlet-name>
|
||||
<url-pattern>/</url-pattern>
|
||||
</servlet-mapping>
|
||||
</web-app>
|
Loading…
Reference in New Issue