0
問題:在嵌入式Jetty中託管彈簧web服務。
這需要適用於單元測試和產品環境。應用程序打包在一個jar中,入口點啓動除Jetty之外的其他服務。在WEB-INF上使用WAR文件/ setwar/WebApplicationContext不是一個選項,因爲包是jar。在嵌入式碼頭中託管彈簧web服務
問題:在嵌入式Jetty中託管彈簧web服務。
這需要適用於單元測試和產品環境。應用程序打包在一個jar中,入口點啓動除Jetty之外的其他服務。在WEB-INF上使用WAR文件/ setwar/WebApplicationContext不是一個選項,因爲包是jar。在嵌入式碼頭中託管彈簧web服務
Server jettyServer = new Server(8080);
DispatcherServlet springServlet = new DispatcherServlet();
springServlet.setContextConfigLocation("classpath:spring-servlet.xml");
final ServletContextHandler contextHandler = new
ServletContextHandler(ServletContextHandler.SESSIONS);
contextHandler.setContextPath("/");
contextHandler.addServlet(new ServletHolder(springServlet), "/*");
jettyServer.setHandler(contextHandler);
contextHandler.getInitParams().put("contextConfigLocation", "classpath:applicationContext.xml");
ContextLoaderListener listener = new ContextLoaderListener();
contextHandler.addEventListener(listener);
jettyServer.start();
jettyServer.join();
AFAIK,這不會給你很多SpringMVC使用的JSP支持。 – Jason 2012-11-22 23:52:00