解决springboot+thymeleaf视图映射报错There was an unexpected error (type=Not Found, status=404)
springboot+thymeleaf视图映射报错
报错There was an unexpected error (type=Not Found, status=404)
在springboot上使用thymeleaf框架搭建前端时,新手可能会出现Whitelabel Error Page,404的问题。
查找了很多网上资料,指出要么是配置问题,要么是没有导入依赖,都没能解决问题。
其实如果使用thymeleaf,问题基本是不会出在配置上的,最可能的原因其实是出在依赖上面,但不是有没有导入的问题,而是导入的依赖是哪个版本的问题。
我原先在pom.xml文件中导入的thymeleaf版本是
<dependency> <groupId>org.thymeleaf</groupId> <artifactId>thymeleaf-spring4</artifactId> <!-- 如果spring是5:thymeleaf-spring5 --> <version>3.0.9.RELEASE</version> </dependency>
结果是会报错的。
后来改成下面springboot的thymeleaf版本后
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
结果是成功的。
当然,在前面一个版本有提到“如果spring是5:thymeleaf-spring5”,按道理来说,我的spring版本是5,应该是可以编译成功的,但实际上,改成thymeleaf-spring5后却是没法通过构建的,具体原因不清楚。
因此,为了保险起见,各位在springboot中使用thymeleaf时最好还是直接使用spring-boot-starter-thymeleaf这种版本,让它自动判断所需的版本,省的各种麻烦。
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
- 如何解决springboot启动的时候required a bean of type 'XXX' not be问题
- SpringBoot中MyBatis使用自定义TypeHandler的实现
- SpringBoot3.1.2 引入Swagger报错Type javax.servlet.http.HttpServletRequest not present解决办法
- SpringBoot升级3.2报错Invalid value type for attribute ‘factoryBeanObjectType‘: java.lang.String的解决方案
- SpringBoot中TypeExcludeFilter的作用及使用方式
相关文章
java中使用雪花算法(Snowflake)为分布式系统生成全局唯一ID代码示例
Java雪花算法是一种用于生成唯一ID的算法,它可以在分布式系统中生成全局唯一的ID,这篇文章主要给大家介绍了关于java中使用雪花算法(Snowflake)为分布式系统生成全局唯一ID的相关资料,需要的朋友可以参考下2024-07-07
Spring Cloud分布式定时器之ShedLock的实现
这篇文章主要介绍了Spring Cloud分布式定时器之ShedLock的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2021-03-03
SpringBoot应用实现向钉钉发送带图片的消息的两种方法总结
在Spring Boot应用中向钉钉发送带图片的消息,主要有两种主流实现方式,一个是使用机器人Webhook,一个是通过钉钉开放平台SDK,下面我们就来看看具体实现步骤吧2025-10-10


最新评论