Springboot 使用thymeleaf 服务器无法加载resources中的静态资源异常处理

这篇具有很好参考价值的文章主要介绍了Springboot 使用thymeleaf 服务器无法加载resources中的静态资源异常处理。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

一、异常错误

Springboot使用thymeleaf,并连接远程数据库启动时,无法加载resources中的静态资源

浏览器报错

Failed to load resource: the server responded with a status of 404 ()

request processing failed; nested exception is org.thymeleaf.exceptions.temp,Java Spring,spring boot,服务器,java

后端启动时报错

Servlet.service() for servlet [dispatcherServlet] in context with path [/ce] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: Error resolving template 

request processing failed; nested exception is org.thymeleaf.exceptions.temp,Java Spring,spring boot,服务器,java
前端打开页面时后端报错

Exception processing template "/web/studyOutline/studyOutline": Error resolving template [/web/studyOutline/studyOutline], template might not exist or might not be accessible by any of the configured Template Resolvers

request processing failed; nested exception is org.thymeleaf.exceptions.temp,Java Spring,spring boot,服务器,java

二、原因

打包编译项目,显示找不到js、css、html等静态资源,但本地路径并没有写错,于是我去找编译文件,查看是不是静态资源没有编译到,打开项目下的target文件夹

request processing failed; nested exception is org.thymeleaf.exceptions.temp,Java Spring,spring boot,服务器,java
前往classes文件夹,发现项目resources下对应的templates韦文件夹没有编译到,缺少静态资源,当然会报错了

request processing failed; nested exception is org.thymeleaf.exceptions.temp,Java Spring,spring boot,服务器,java
request processing failed; nested exception is org.thymeleaf.exceptions.temp,Java Spring,spring boot,服务器,java

三、解决方法

方法1. 将无法编译的静态资源放入可编译目录下

既然服务器不能编译templates文件夹,那么把templates文件夹放入calsses路径下即可,这样处理就能获取templats下的静态资源了,但如果静态资源有改动,需要手动放入classes文件夹下,再次启动项目即可读取资源

request processing failed; nested exception is org.thymeleaf.exceptions.temp,Java Spring,spring boot,服务器,java
如果再次启动项目,还是显示找不到js、css、html等静态资源,请看方法2

方法2. 重新编译项目加载资源

由于服务器编译拦截了静态资源,导致出现异常,需要重新打包编译

打开IDEA带的Maven管理,双击clean清除由项目编译创建的target

再双击install安装jar包到本地仓库
request processing failed; nested exception is org.thymeleaf.exceptions.temp,Java Spring,spring boot,服务器,java

项目打包出现异常

[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.

request processing failed; nested exception is org.thymeleaf.exceptions.temp,Java Spring,spring boot,服务器,java

系统默认编码是GBK,maven提升需要使用UTF-8,在setting中修改项目编码为UTF-8

request processing failed; nested exception is org.thymeleaf.exceptions.temp,Java Spring,spring boot,服务器,java

request processing failed; nested exception is org.thymeleaf.exceptions.temp,Java Spring,spring boot,服务器,java

出现 Failed to execute goal是由于测试用例有问题,

 Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-test) on project springboot_04_profile: Input length = 1 -> [Help 1]

request processing failed; nested exception is org.thymeleaf.exceptions.temp,Java Spring,spring boot,服务器,java

选择跳过测试用例

request processing failed; nested exception is org.thymeleaf.exceptions.temp,Java Spring,spring boot,服务器,java

再次双击install,编译成功,启动项目即可读取静态资源

request processing failed; nested exception is org.thymeleaf.exceptions.temp,Java Spring,spring boot,服务器,java
如果设置编码还是打包失败,或者显示找不到js、css、html等静态资源,请看方法3

方法3. 修改pom.xml资源配置文件

如果设置编码还是打包失败,或者显示找不到js、css、html等静态资源,说明服务器没有访问资源的权限,需要在pom.xml的build下引入资源文件

<!--           引入静态资源文件   -->
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.css</include>
                    <include>**/*.js</include>
                    <include>**/*.html</include>
                    <include>**/*.png</include>
                    <include>**/*.properties</include>
                    <include>**/*.yml</include>
                    <include>**/*.xml</include>
                    <include>**/*.conf</include>
                </includes>
            </resource>
        </resources>

再次insall,显示打包成功,浏览器404的问题也解决了,加载了静态资源

request processing failed; nested exception is org.thymeleaf.exceptions.temp,Java Spring,spring boot,服务器,java

方法4. 不连接远程数据库启动,使用本地数据库

开头说了,Springboot使用thymeleaf,并连接远程数据库启动时,无法加载resources中的静态资源,这是一个大坑,如果不连接远程数据库启动,则不存在服务器访问资源的问题

打开application.properties配置文件,注释掉连接远程数据库的代码,改用本地数据库,就不会有访问资源的问题了,可以直接加载,浏览器不再出现Failed to load resource问题

request processing failed; nested exception is org.thymeleaf.exceptions.temp,Java Spring,spring boot,服务器,java

异常索引文章来源地址https://www.toymoban.com/news/detail-763240.html

  • Failed to load resource: the server responded with a status of 404 ()
  • Servlet.service() for servlet [dispatcherServlet] in context with path [/ce] threw exception [Request processing failed; nested
    exception is org.thymeleaf.exceptions.TemplateInputException: Error
    resolving template
  • Exception processing template “/web/studyOutline/studyOutline”: Error resolving template [/web/studyOutline/studyOutline], template
    might not exist or might not be accessible by any of the configured
    Template Resolvers
  • [INFO] Using ‘UTF-8’ encoding to copy filtered resources. [INFO] Using ‘UTF-8’ encoding to copy filtered properties files.
  • Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources
    (default-test) on project springboot_04_profile: Input length = 1 ->
    [Help 1]

到了这里,关于Springboot 使用thymeleaf 服务器无法加载resources中的静态资源异常处理的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 解决国内Linux服务器无法使用Github的方法

    解决思路:修改Host https://www.ipaddress.com/ 利用上面的网站查询github.com和raw.githubusercontent.com的DNS解析的IP地址 最后,修改服务器的/etc/hosts 添加如下两行: 140.82.112.3 github.com 185.199.108.133 raw.githubusercontent.com 这是最新的IP地址,如果更改之后还无法git clone的话,可能IP地址又更新

    2024年01月20日
    浏览(43)
  • 内网服务器(无法联网)使用docker搭建自己的NAS服务(filebrowser)

    课题组内有一台内网部署的ubuntu 23服务器,想要在上面运行一个NAS服务,供内网环境中的文件存储与分享。希望搭建一个功能简单、容易上手的NAS服务,并且希望通过docker部署,减少对于服务器上现有应用的影响。另外,内网服务器意味着它无法连接互联网下载应用,只能在

    2024年03月16日
    浏览(37)
  • 解决websocket在部署到服务器https下无法使用的问题

    目录 一、问题 1.1 问题描述 1.2 问题详细描述 二、解决 2.1 https下的链接类型 2.2 修改Nginx的配置 一个小项目中使用到了websocket,这个websocket在本地完全是完全正常运行的,不管是 前后台的信息通讯  还是 异常报错接收 , 无任何异常 ,但当把后台代码部署到阿里云服务器后

    2024年02月09日
    浏览(21)
  • 网上邻居打不开提示工作组的服务器列表无法使用

    小编的好友说之前能通过网上邻居浏览别人的共享文件,不知道怎么了,最近一直无法打开网上邻居.提示“此工作组的服务器列表当前无法使用”,重启几次都无法解决.是什么原因. 一些软件的开机加速优化会建议禁止“Gomputer Browser(计算机列表)”这个服务,没有这个服务就可能

    2024年02月06日
    浏览(37)
  • SpringBoot如何使用MultipartFile进行文件上传保存到服务器本地

    之前一直都是用的别人封装好的文件上传方法,这次想自己写一个特别简单的,文件上传方法,非常适合新手观看… 首先需要Springboot需要有Web依赖,就是下面这个依赖 依赖导完了,下面就直接是代码,大家看一下 到这里文件上传的解释都在代码里面,下面如果报文件过大的报错还需

    2024年02月13日
    浏览(48)
  • Linux中关于glibc包导致的服务器死机或者linux命令无法使用的情况

    glibc是gnu发布的libc库,即c运行库。 glibc是linux系统中最底层的api,几乎其它任何运行库都会依赖于glibc 。glibc除了封装linux操作系统所提供的系统服务外,它本身也提供了许多其它一些必要功能服务的实现。由于 glibc 囊括了几乎所有的 UNIX 通行的标准,可以想见其内容包罗万

    2024年02月03日
    浏览(39)
  • 云服务器使用jenkins+docker自动化部署SpringBoot项目

    docker 安装jenkins,就这一步都恶心死了 //拉取镜像,踩了很多坑,用其它版本的镜像插件一直安装失败,最后用的是lts版本(基础版) 用其它版本要么是连不上插件的下载地址,要么是插件下载不成功  docker pull jenkins/jenkins:lts  部署 docker run --user root -d -p 10240:8080 -p 10241:50

    2024年02月01日
    浏览(41)
  • MySQL 的服务器安装及使用,springboot源码深度解析pdf

    SELECT * FROM users WHERE uname in (‘zs’,‘ls’) 排序 order by 要写在 sql 语句的最后 – asc 升序 desc 降序 SELECT * FROM users ORDER BY DESC SELECT * FROM users WHERE uage 18 ORDER by desc 限制查询条数 – 取前3条数据 SELECT * FROM users LIMIT 3 – 降序后去3条数据 SELECT * FROM users ORDER BY DESC LIMIT 3 – 跳过3条,

    2024年04月14日
    浏览(24)
  • Springboot中使用内嵌服务器运行 WAR 文件的探索之路

    🌷🍁 博主猫头虎 带您 Go to New World.✨🍁 🦄 博客首页——猫头虎的博客🎐 🐳《面试题大全专栏》 文章图文并茂🦕生动形象🦖简单易学!欢迎大家来踩踩~🌺 🌊 《IDEA开发秘籍专栏》学会IDEA常用操作,工作效率翻倍~💐 🌊 《100天精通Golang(基础入门篇)》学会Golang语言

    2024年02月21日
    浏览(27)
  • 手动将Java SpringBoot项目部署到云服务器上(使用docker)

    本文记录一下我作为一个小白如何通过docker手动将java springboot项目部署到云服务器上(以腾讯云的轻量应用服务器为例)。 但是我个人还是推荐安装一个宝塔面板部署 ,真的全程自动化,非常方便,网上有很多相关的教程可以搜搜看。所以我写这个教程其实只想记录一下我

    2024年04月25日
    浏览(32)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包