一 thymeleaf-layout-dialect 版本
在Spring Boot 2.6.x以后版本需要使用3.0.0,同时暂时不能使用3.1.0。2.6.x后Spring Boot有对改组件的版本管理,所以配置添加配置的时候不需要配置版本即可
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
<!-- <version>2.4.1</version>-->
</dependency>
二 全局循环依赖解决配置
The dependencies of some of the beans in the application context form a cycle:
spring
main:
allow-circular-references: true #自动解决循环依赖问题
三 资源文件映射配置变化
spring
resources:
static-locations: classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/
升级到2.6.x 2.7.x 后
spring
resources: #本地资源映射配置
static-locations: classpath:/static/,file:${app.file-root}/header #参考配置
四 mvc pathmatch 解决springfox swagger 初始化报错问题
spring boot 2.7.x修改了mvc默认的path匹配器,默认是
path_pattern_parser
ant_path_matcher
配置如下:
spring
pathmatch:
matching-strategy: ant_path_matcher #解决springfox swagger问题
五 ErrorController 接口去掉了getErrorPath方法
删除实现的getErrorPath()方法即可。
六 页面跳转错误
错误信息参考:
Cannot forward to error page for request [/a/] as the response has already been committed. As a result, the response may have the wrong status code. If your application is running on WebSphere Application Server you may be able to resolve this problem by setting com.ibm.ws.webcontainer.invokeFlushAfterService to false org.springframework.boot.web.servlet.support.ErrorPageFilter.handleCommittedResponse(ErrorPageFilter.java:219)
如果使用的不是 四 中的路径匹配器,是默认的,需要注意 以下写法对应不一样
以上对于新的匹配器来说是两个不同的路径。
六 跨域配置问题
Caused by: java.lang.IllegalArgumentException: When allowCredentials is true, allowedOrigins cannot contain the special value "*" since that cannot be set on the "Access-Control-Allow-Origin" response header. To allow credentials to a set of origins, list them explicitly or consider using "allowedOriginPatterns" instead.
上面是因为我使用了@CrossOrigin(allowCredentials = "true")注解。
解决办法是:
设置注解中的originPatterns为* ,不使用默认的 allowedOrigins *
@CrossOrigin(allowCredentials = "true",originPatterns = "*")
如果你是代码全局配置的,则修改下面注释掉的地方即可
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
// .allowedOrigins("*") //修改为下面的
.allowedOriginPatterns("*")
.allowedMethods("GET","POST","PUT","DELETE","OPTIONS")
.allowCredentials(true)
.maxAge(3600)
.allowedHeaders("*");