当前位置: 首页 > 知识库问答 >
问题:

带磁贴的Spring引导:部署为jar时找不到静态web资源

林元明
2023-03-14

我已经用Web MVC将Java JSP Tomcat Web应用程序迁移到Spring boot。我可以在IDE中运行应用程序(EclipseMars2)。一切正常。我已经用嵌入式tomcat创建了一个可执行的jar文件。应用程序启动时没有错误,但是如果我访问了一个页面,tiles框架会因为丢失而抛出一个异常。jsp文件。

在SO I read上的其他帖子中,有一些用于静态webcontent(/META-INF/resources/,/resources/,/static/,/public/)的特殊文件夹。我尝试使用静态文件夹,但在本例中,在Eclipse中运行时也没有找到jsp内容。

所需的文件确实存在于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>

瓷砖。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.NestedServletExcture:请求处理失败;嵌套异常org.apache.tiles.request.render.CannotRenderExcture: Servl etExcture包括path'/jsp/Fronader/Public/布局/Layout.jsp'. atorg.springframework.web.servlet.FrameworkServlet.process请求(FrameworkServlet.java:982)~[sping-webmvc-4.3.13.发布. jar!/: 4.3.13.发布]在org.springframework.web.servlet.FrameworkServlet.do获取(FrameworkServlet.java:861)~[sping-webmvc-4.3.13。发布. jar!/: 4.3.13.发布]在javax.servlet.http.HttpServlet.service(HttpServlet.java:635)~[tomcat-embed-core-8.5.23.jar!org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)~发布. jar!/: 4.3.13.发布]javax.servlet.http.HttpServlet.service(HttpServlet.java:742)~[tomcat-embed-core-8.5.23.jar!/: 8.5.23]at org. apache. catalina. core.[tomcat-embed-core-8.5.23. jar!]/: 8.5.23]at org. apache. catalina. core.应用过滤链. doFilter(应用过滤链. java: 166)~[tomcat-embed-core-8.5.23. jar!/: 8.5.23]at org. apache. catalina. core.Application ationDispatcher. invoke(Application ationDispatcher. java: 728)~[tomcat-embed-core-8.5.23. jar!/: 8.5.23]at org. apache. catalina. core.应用程序请求(应用程序请求. java: 469)~[tomcat-embed-core-8.5.23. jar!/: 8.5.23]at org. apache. catalina. core.Application ationDispatcher. doForward(Application ationDispatcher. java: 392)~[tomcat-embed-core-8.5.23. jar!/: 8.5.23]at org. apache. catalina. core.[tomcat-embed-core-8.5.23. jar!]/: 8.5.23]at org. apache. catalina. core.[tomcat-embed-core-8.5.23. jar!]/: 8.5.23]at org. apache. catalina. core.[tomcat-embed-core-8.5.23. jar!]/: 8.5.23]at org. apache. catalina. core.[tomcat-embed-core-8.5.23. jar!]/: 8.5.23]at org. apache. catalina. valves.[tomcat-embed-core-8.5.23. jar!]/: 8.5.23]at org. apache. catalina. core.[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. coyot. http 11.java: 803)[tomcat-embed-core-8.5.23. jar!/: 8.5.23]at org. apache. coyote.进程(AbstractProcessorLight. java: 66)[tomcat-embed-core-8.5.23. jar!/: 8.5.23]at org. apache. coyote.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]在java. util. con当前。ThreadPoolExecutor. runWorker(未知来源)[na: 1.8.0_144]at java. util. con当前。线程池执行器$Worker. run(未知来源)[na: 1.8.0_144]at org. apache. tomcat. util. thon。TaskThread$WrappingRunnable. run(TaskThread. java: 61)[tomcat-embed-core-8.5.23. jar!/: 8.5.23]at java. lang.线程. run(未知来源)[na: 1.8.0_144]...

造成原因:javax.servlet.Servlet异常:文件[/jsp/前端/公共/布局/Layout.jsp]未在org.apache.jasper.servlet.找到JspServlet.handle失踪资源(JspServlet.java:407)~[tomcat-embed-jasper-8.5.23.jar!org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:374)~[tomcat-embed-jasper-8.5.23.jar!org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)~[tomcat-embed-jasper-8.5.23.jar!javax.servlet.http.HttpServlet.service(HttpServlet.java:742)~[tomcat-embed-core-8.5.23.jar!org.apache.catalina.core.Application ationFilterChain.internalDoFilter(Application ationFilterChain. java: 231)~[tomcat-embed-core-8.5.23. jar!/: 8.5.23]at org. apache. catalina. core.应用过滤链. doFilter(应用过滤链. java: 166)~[tomcat-embed-core-8.5.23. jar!/: 8.5.23]

共有1个答案

呼延珂
2023-03-14

您可以将项目打包转换为可执行war,这样spring就可以找到您的*。jsp

 类似资料:
  • 我在Spring Boot MVC应用程序中使用了Thymeleaf模板引擎,但在加载styless时遇到了困难。链接位于文件(位于参考资料/模板/片段下),并在登录中引用。html(在参考资料/模板下)。样式表位于resources/static/css目录中。 登录。html 基于这个问题和其他来源,应用程序似乎应该能够使用指定的链接加载样式表。然而,情况并非如此。具体地说,如果我查看浏览器的

  • 正在尝试在linux服务器上部署spring启动应用程序 r,“线程名称”:“localhost-startStop-1”,“级别”:“错误”,“级别值”:40000,“堆栈跟踪”:“组织”。springframework。豆。工厂BeanCreationException:创建名为“org”的bean时出错。springframework。验证。Bean验证。OptionalValidatorF

  • 我有一个项目,我正试图从我的将其部署到。它在windows,但是当我在那里开发时,我在下面得到了这个错误。 从Azure Web应用程序登录: 我尝试过不同的解决方案,包括在我的文件,如下所示: 我怎样才能解决这个问题?

  • 我正在做一个项目,编译并运行我的IDE工作正常。所有资源都找到了,它正常工作。然而,当我构建我的. jar时,它能够找到一些资源,但不是全部。我的项目结构看起来是这样的: 当我运行jar文件时,它能够找到图像并使用它们,但是当我尝试访问html文件时,它不会打开。下面是jar的项目结构; 我以前从未处理过jar文件,所以这似乎是我犯的一个非常明显的错误。感谢您的帮助,谢谢! 编辑:访问找不到的文件

  • 我使用SpringBootMaven插件将应用程序打包为jar文件。 它可以在Itellij IDE中找到直接运行的资源文件,但之后找不到资源文件,显示错误为: JAVA木卫一。FileNotFoundException:类路径资源[jmxremote.password]无法解析为绝对文件路径,因为它不位于文件系统:jar:file:/home/XXX/target/yyyy中。罐子/BOOT-I

  • 问题内容: 我正在尝试将请求映射到servlet根(正确的术语?)。我正在将URL映射到正确的视图,但是找不到页面的一部分的所有静态内容-CSS,JavaScript,图像。 所以在我的web.xml中,我的servlet标记看起来像这样 我的控制器看起来像这样: MyBaseController非常简单。看起来像这样: 我在视图层中使用了Tiles。我的配置如下: /WEB-INF/tiles-