首页 新闻 会员 周边 捐助

springboot 部署服务器运行的错误

0
悬赏园豆:30 [待解决问题]

springboot项目中含有一个页面——FuncPepStatistics.html,该页面的内容由echarts.js写的js代码生成的统计图构成。
该项目在idea中运行后,FuncPepStatistics.html页面是可以成功运行的。
但是,如果将该springboot项目打包后,无论是在本地的cmd上运行,还是在云服务器上运行,该页面都不能成功显示,出现的错误是500类型的错误
浏览器的控制台给出以下报错:
Failed to load resource: the server responded with a status of 500 ()
Uncaught (in promise) Error: A listener indicated an asynchronous response by returning true, but the message channel closed before a response was received
服务器终端的报错如下:
[THYMELEAF][http-nio-9188-exec-9] Exception processing template "/FuncPepStatistics": Error resolving template [/FuncPepStatistics], template might not exist or might not be accessible by any of the configured Template Resolvers
org.thymeleaf.exceptions.TemplateInputException: Error resolving template [/FuncPepStatistics], template might not exist or might not be accessible by any of the configured Template Resolvers

Servlet.service() for servlet [dispatcherServlet] in context with path [/mfppdb] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: Error resolving template [/FuncPepStatistics], template might not exist or might not be accessible by any of the configured Template Resolvers] with root cause
org.thymeleaf.exceptions.TemplateInputException: Error resolving template [/FuncPepStatistics], template might not exist or might not be accessible by any of the configured Template Resolvers

思存、的主页 思存、 | 初学一级 | 园豆:172
提问于:2023-04-08 23:20
< >
分享
所有回答(1)
0

根据服务器终端的报错信息,可以看出 Thymeleaf 模板引擎在解析页面时发生了错误,提示无法找到名为 "/FuncPepStatistics" 的模板文件。这可能是由于页面所依赖的静态资源没有正确地打包或部署到了指定的目录中,导致服务器无法找到该页面的资源文件。

具体来说,可以按照以下步骤进行排查:

检查静态资源是否正确打包到了 Jar 包中。
使用打包命令打包应用程序时,需要确保在 pom.xml 或 build.gradle 文件中配置了正确的构建配置。特别是,需要将所有的静态资源(例如 FuncPepStatistics.html、JS、CSS 等)都包含在 jar 包中。可以在 Jar 包中查看是否包含了这些文件。如果未正确打包,可以尝试在配置文件中添加以下代码,将静态资源打包到 Jar 包中:

xml

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeResources>true</includeResources>
</configuration>
</plugin>
</plugins>
</build>
检查页面访问路径是否正确
检查请求的路径是否正确,以及是否有拼写错误。例如,如果访问路径是 "/FuncPepStatistics.html",那么在浏览器中输入该路径时,需要确保输入的路径正确,不要遗漏 ".html" 后缀等。

检查 Thymeleaf 模板引擎配置是否正确
如果在应用程序中使用了 Thymeleaf 模板引擎来渲染页面,需要确保模板引擎的配置正确。在配置文件中,可以添加以下代码来配置模板引擎的模板解析器:

yaml

spring:
thymeleaf:
prefix: classpath:/templates/
suffix: .html
cache: false
encoding: UTF-8
其中,prefix 指定了模板文件所在的路径,suffix 指定了模板文件的后缀名,cache 指定了是否启用缓存,encoding 指定了编码方式。

如果以上排查方法均未解决问题,建议进一步检查应用程序的日志文件,查看是否有其他的错误信息,以帮助定位问题的根本原因。

Technologyforgood | 园豆:7231 (大侠五级) | 2023-04-09 08:53

谢谢您的回复,我尝试了您提供的方法,但是依然不能解决这个问题。

支持(0) 反对(0) 思存、 | 园豆:172 (初学一级) | 2023-04-09 11:57
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册