我有一個Spring MVC應用程序,我使用休眠,freemarker。它被設置爲一個多Maven項目。我正在使用IntelliJ Ultimate。碼頭不拿起我的彈簧應用程序
碼頭開始很好,但是當我去
http://localhost:8080/
它只是輸出我的項目的文件夾,我可以在瀏覽器中查看我的源代碼!
這是目前我的設置:
final Server server = new Server(8080);
ProtectionDomain domain = HttpServer.class.getProtectionDomain();
URL location = domain.getCodeSource().getLocation();
WebAppContext webAppContext = new WebAppContext();
webAppContext.setResourceBase(location.toExternalForm());
webAppContext.setDescriptor(location.toExternalForm() + "/WEB-INF/web.xml");
webAppContext.setContextPath("/");
webAppContext.setParentLoaderPriority(true);
server.setHandler(webAppContext);
server.start();
server.join();
我的項目佈局(使用INTELLI J)的佈局就像是一個多Maven項目:
/myapp/src/main/java/main.java (this contains the above code to start jetty)
/myapp/src/main/webapp
/myapp/src/main/webapp/assets
/myapp/src/main/webapp/WEB-INF
/myapp/src/main/webapp/WEB-INF/web-context.xml (spring config file)
/myapp/src/main/webapp/WEB-INF/web.xml
/myapp/src/main/webapp/WEB-INF/views/ (parent folder for my freemarker template files)
/myapp/src/main/webapp/WEB-INF/views/home/index.ftl
我的web.xml文件是:
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath*:log4j.properties</param-value>
</context-param>
<servlet>
<servlet-name>myapp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/web-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>myapp</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
當我在的IntelliJ(11 ulimitate)運行它,我得到以下的輸出:
2012-08-15 19:17:11,611 [main] INFO org.eclipse.jetty.server.Server - jetty-7.6.2.v20120308
2012-08-15 19:17:11,886 [main] INFO org.eclipse.jetty.webapp.StandardDescriptorProcessor - NO JSP Support for /, did not find org.apache.jasper.servlet.JspServlet
2012-08-15 19:17:11,962 [main] INFO org.eclipse.jetty.server.handler.ContextHandler - started o.e.j.w.WebAppContext{/,file:/Users/me/projects/myapp/myapp-web/target/classes/}
2012-08-15 19:17:12,021 [main] INFO org.eclipse.jetty.server.AbstractConnector - Started [email protected]:8080
這顯然是行不通的,因爲當我使用TomcatW¯¯運行/的IntelliJ我得到的東西像冬眠,春天的巨大輸出等
我對Web模塊的pom.xml有:
..
<packaging>war</packaging>
..
看看這可能有幫助(它的工作原理) - > http://stackoverflow.com/a/10609507/169277 – ant 2012-08-15 23:25:30
這是生產的權利?不是爲了本地發展?我看到scanInterval,以便看起來像一個開發設置(以防它是不同的?) – Blankman 2012-08-15 23:53:41
是的這是爲developmnet – ant 2012-08-17 22:53:20