【发布时间】:2012-08-15 23:18:40
【问题描述】:
我有一个使用休眠、freemarker 的 Spring MVC 应用程序。它被设置为一个多 Maven 项目。我正在使用 IntelliJ 终极版。
码头开始很好,但是当我去
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();
我的项目布局是一个多maven项目(使用intelli J),布局是这样的:
/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 SelectChannelConnector@0.0.0.0:8080
这显然是行不通的,因为当我使用带有 IntelliJ 的 tomcat 运行它时,我得到了一个巨大的输出,比如休眠、弹簧等。
我的 web 模块的 pom.xml 有:
..
<packaging>war</packaging>
..
【问题讨论】:
-
看看这是否有帮助(它有效)-> stackoverflow.com/a/10609507/169277
-
那是为了生产对吧?不是为了本地发展?我看到 scanInterval 看起来像是一个开发设置(如果它不同?)
-
我不想在开发模式下运行码头,这是为了生产。
-
您要运行分解的 WAR 还是 WAR 本身?无论哪种情况,这些资源的绝对路径是什么,您是否确认
URL location指向那里?
标签: java spring spring-mvc jetty