我正在尝试在我的测试类中启动嵌入式Jetty。我写了那段代码:
server = new Server(TEST_PORT);
ServletHolder sh = new ServletHolder(ServletContainer.class);
sh.setInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig");
sh.setInitParameter("com.sun.jersey.config.property.packages", "org.gogo.rena.rest");
sh.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", "true");
ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS);
context.setContextPath("/");
context.addServlet(sh, "/*");
server.setHandler(context);
try {
server.setStopAtShutdown(true);
server.start();
//server.join();
} catch (Exception e) {
fail("Error has occurred while starting! Error is as follows: " + e.getMessage());
}
如何将application-context-test.xml和web.xml指向我的嵌入式Jetty(它们位于不同的地方。)
答案 0 :(得分:0)
我认为您不需要web.xml,因为您正在使用嵌入式Jetty。我知道Spring Boot你不需要它。我想你手动配置你的servlet。至于你的App Context,它是否在classpath中?不应该在DispatchServlet中读取它吗?