解决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的作用及使用方式
相关文章
Spring之AOP两种代理机制对比分析(JDK和CGLib动态代理)
这篇文章主要介绍了Spring之AOP两种代理机制对比分析(JDK和CGLib动态代理),具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教2023-05-05
使用Lombok导致打印的tostring中缺少父类的属性问题
使用Lombok时,若发现@Data注解的@ToString不包含父类属性,可通过添加@ToString(callSuper=true)解决,此方法确保在生成toString()时包括父类的属性,有效解决只打印子类属性的问题,这种做法对于需要完整信息展示的场景尤为重要2024-11-11
SpringMVC中的ResourceUrlProviderExposingInterceptor详解
这篇文章主要介绍了SpringMVC中的ResourceUrlProviderExposingInterceptor详解,ResourceUrlProviderExposingInterceptor是Spring MVC的一个HandlerInterceptor,用于向请求添加一个属性,需要的朋友可以参考下2023-12-12


最新评论