我已经使用Web MVC将Java-JSP-Tomcat WebApplication迁移到Spring启动。我可以在IDE中运行应用程序(eclipse Mars 2)。一切都很好。我已经创建了一个带有嵌入式tomcat的可执行jar文件。应用程序启动时没有错误,但是如果我访问页面,则tiles-framework会因为缺少.jsp文件而抛出异常。
在SO上的其他帖子中我读到,有静态webcontent的特殊文件夹(/ META-INF / resources /,/ resources /,/ static /,/ public /)。我曾尝试使用static-folder,但在这种情况下,找不到jsp-content,在Eclipse中运行时也是如此。
jar文件中确实存在所需的文件。我已经控制了很多次。
项目结构:
的pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>webapp</artifactId>
<version>2.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name> WebApp</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!-- needed to run as service under linux (start|stop|status) -->
<executable>true</executable>
</configuration>
</plugin>
</plugins>
</build>
</project>
tiles.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
"http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
<tiles-definitions>
<definition name="public.definition" template="/jsp/frontend/public/layout/Layout.jsp">
<put-attribute name="title" value="WebApp" />
<put-attribute name="topNav" value="/jsp/frontend/public/layout/TopNav.jsp" />
<put-attribute name="header" value="/jsp/frontend/public/layout/Header.jsp" />
<put-attribute name="menu" value="/jsp/frontend/public/layout/MainMenu.jsp" />
<put-attribute name="body" value="" />
<put-attribute name="footer" value="/jsp/frontend/public/layout/Footer.jsp" />
</definition>
<definition name="singlePage.definition" template="/jsp/frontend/public/layout/LayoutSinglePage.jsp">
<put-attribute name="content" value="" />
</definition>
<definition name="privacySinglePage" extends="singlePage.definition">
<put-attribute name="content" value="/jsp/frontend/public/privacy.jsp" />
</definition>
<definition name="privacy" extends="public.definition">
<put-attribute name="body" value="/jsp/frontend/public/privacy.jsp" />
</definition>
<definition name="imprint" extends="public.definition">
<put-attribute name="body" value="/jsp/frontend/public/imprint.jsp" />
</definition>
...
</tiles-definitions>
异常
org.springframework.web.util.NestedServletException:请求处理失败;嵌套异常是org.apache.tiles.request.render.CannotRenderException:Servl etException包括path&#39; /jsp/frontend/public/layout/Layout.jsp'。 在org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982)〜[spring-webmvc-4.3.13.RELEASE.jar!/:4.3.13.RELEASE] 在org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)〜[spring-webmvc-4.3.13.RELEASE.jar!/:4.3.13.RELEASE] 在javax.servlet.http.HttpServlet.service(HttpServlet.java:635)〜[tomcat-embed-core-8.5.23.jar!/:8.5.23] 在org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)〜[spring-webmvc-4.3.13.RELEASE.jar!/:4.3.13.RELEASE] 在javax.servlet.http.HttpServlet.service(HttpServlet.java:742)〜[tomcat-embed-core-8.5.23.jar!/:8.5.23] 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)〜[tomcat-embed-core-8.5.23.jar!/:8.5.23] 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)〜[tomcat-embed-core-8.5.23.jar!/:8.5.23] at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:728)~ [tomcat-embed-core-8.5.23.jar!/:8.5.23] 在org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:469)〜[tomcat-embed-core-8.5.23.jar!/:8.5.23] 在org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:392)〜[tomcat-embed-core-8.5.23.jar!/:8.5.23] 在org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:311)〜[tomcat-embed-core-8.5.23.jar!/:8.5.23] 在org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:395)[tomcat-embed-core-8.5.23.jar!/:8.5.23] 在org.apache.catalina.core.StandardHostValve.status(StandardHostValve.java:254)[tomcat-embed-core-8.5.23.jar!/:8.5.23] 在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:177)[tomcat-embed-core-8.5.23.jar!/:8.5.23] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)[tomcat-embed-core-8.5.23.jar!/:8.5.23] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)[tomcat-embed-core-8.5.23.jar!/:8.5.23] 在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)[tomcat-embed-core-8.5.23.jar!/:8.5.23] 在org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)[tomcat-embed-core-8.5.23.jar!/:8.5.23] 在org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)[tomcat-embed-core-8.5.23.jar!/:8.5.23] at org.apache.coyote.AbstractProtocol $ ConnectionHandler.process(AbstractProtocol.java:868)[tomcat-embed-core-8.5.23.jar!/:8.5.23] 在org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.doRun(NioEndpoint.java:1459)[tomcat-embed-core-8.5.23.jar!/:8.5.23] 在org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)[tomcat-embed-core-8.5.23.jar!/:8.5.23] at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)[na:1.8.0_144] at java.util.concurrent.ThreadPoolExecutor $ Worker.run(Unknown Source)[na:1.8.0_144] at org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61)[tomcat-embed-core-8.5.23.jar!/:8.5.23] at java.lang.Thread.run(Unknown Source)[na:1.8.0_144] ...
引起:javax.servlet.ServletException:找不到文件[/jsp/frontend/public/layout/Layout.jsp] 在org.apache.jasper.servlet.JspServlet.handleMissingResource(JspServlet.java:407)〜[tomcat-embed-jasper-8.5.23.jar!/:8.5.23] 在org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:374)〜[tomcat-embed-jasper-8.5.23.jar!/:8.5.23] 在org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)〜[tomcat-embed-jasper-8.5.23.jar!/:8.5.23] 在javax.servlet.http.HttpServlet.service(HttpServlet.java:742)〜[tomcat-embed-core-8.5.23.jar!/:8.5.23] 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)〜[tomcat-embed-core-8.5.23.jar!/:8.5.23] 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)〜[tomcat-embed-core-8.5.23.jar!/:8.5.23]
答案 0 :(得分:0)
您可以将项目包装转换为可执行的战争,以便spring可以找到您的* .jsp