如题,看到网上很多将Jetty作为一个bean和Spring一起运行的,和我的需求不相符。
目前,我需要在测试用例中测试一个SpringMVC工程,测试用例在单独的工程中,jetty无法接收到页面的请求,请教该如何写?private static final String DEFAULT_CONTEXTPATH = "/"; private static final String DEFAULT_DESCRIPTOR = "/WEB-INF/web.xml"; private String location; private String contextPath; private Server server; public JettySupport(String location, String contextPath) {
this.location = location;
this.contextPath = contextPath;
} private Server initServerIfNecessary() {
if (server != null)
return server;
server = new Server();
SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(8080);
connector.setHost("127.0.0.1");
server.addConnector(connector);
location = location.endsWith("/") ? location.substring(0, location.length() - 1) : location;
WebAppContext context = new WebAppContext();
context.setContextPath(DEFAULT_CONTEXTPATH + this.contextPath);
context.setDescriptor(location + DEFAULT_DESCRIPTOR);
context.setResourceBase(location);
server.addHandler(context);
return server;
} public void start() throws Exception {
initServerIfNecessary();
server.start();
} public void stop() throws Exception {
if (server == null)
return;
server.stop();
}