gpt4 book ai didi

带 Tiles : static webresources not found when deploying as jar 的 Spring Boot

转载 作者:行者123 更新时间:2023-11-28 23:17:31 25 4
gpt4 key购买 nike

我已经使用 Web MVC 将 Java-JSP-Tomcat WebApplication 迁移到 Spring boot。我可以在 IDE (eclipse Mars 2) 中运行该应用程序。一切正常。我创建了一个带有嵌入式 tomcat 的可执行 jar 文件。应用程序启动时没有错误,但如果我访问页面,tiles-framework 会因缺少 .jsp 文件而抛出异常。

在我读到的 SO 上的其他帖子中,有用于静态 Web 内容的特殊文件夹(/META-INF/resources/、/resources/、/static/、/public/)。我曾尝试使用静态文件夹,但在这种情况下找不到 jsp 内容,在 Eclipse 中运行时也是如此。

jar 文件中确实存在所需的文件。我已经控制了很多次。

项目结构:

enter image description here

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: Request processing failed; nested exception is org.apache.tiles.request.render.CannotRenderException: Servl etException including path '/jsp/frontend/public/layout/Layout.jsp'. at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982) ~[spring-webmvc-4.3.13.RELEASE.jar!/:4.3.13.RELEASE] at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) ~[spring-webmvc-4.3.13.RELEASE.jar!/:4.3.13.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:635) ~[tomcat-embed-core-8.5.23.jar!/:8.5.23] at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) ~[spring-webmvc-4.3.13.RELEASE.jar!/:4.3.13.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) ~[tomcat-embed-core-8.5.23.jar!/:8.5.23] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-8.5.23.jar!/:8.5.23] at 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] at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:469) ~[tomcat-embed-core-8.5.23.jar!/:8.5.23] at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:392) ~[tomcat-embed-core-8.5.23.jar!/:8.5.23] at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:311) ~[tomcat-embed-core-8.5.23.jar!/:8.5.23] at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:395) [tomcat-embed-core-8.5.23.jar!/:8.5.23] at org.apache.catalina.core.StandardHostValve.status(StandardHostValve.java:254) [tomcat-embed-core-8.5.23.jar!/:8.5.23] at 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] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) [tomcat-embed-core-8.5.23.jar!/:8.5.23] at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803) [tomcat-embed-core-8.5.23.jar!/:8.5.23] at 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] at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459) [tomcat-embed-core-8.5.23.jar!/:8.5.23] at 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] ...

Caused by: javax.servlet.ServletException: File [/jsp/frontend/public/layout/Layout.jsp] not found at org.apache.jasper.servlet.JspServlet.handleMissingResource(JspServlet.java:407) ~[tomcat-embed-jasper-8.5.23.jar!/:8.5.23] at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:374) ~[tomcat-embed-jasper-8.5.23.jar!/:8.5.23] at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329) ~[tomcat-embed-jasper-8.5.23.jar!/:8.5.23] at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) ~[tomcat-embed-core-8.5.23.jar!/:8.5.23] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-8.5.23.jar!/:8.5.23] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.23.jar!/:8.5.23]

最佳答案

您可以将您的项目打包转换为可执行的war,以便spring 可以找到您的*.jsp

关于带 Tiles : static webresources not found when deploying as jar 的 Spring Boot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47581352/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com