首页> 文章> 详情

Spring Boot 2.3.x 升级到2.7.x 问题和解决

教程分享 > Java教程 (4031) 2024-04-17 10:32:45

升级环境说明

目前项目使用的2.3.7版本(自己感觉还行,但是官方已经停止支持了。)
Spring Boot 官方支持情况

spring boot 官方支持情况
spring boot 官方支持情况


官方在今年8月就终止了对2.3.x的版本支持。2.7.x还有点时间。为啥不升级到3.0.x?太新,不适上线项目使用。
 

  • 当前Spring Boot 版本 2.3.7
  • 升级Spring Boot 版本 2.7.6
  • jdk 版本 1.8

一  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
  web:
    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
  mvc:
    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) 


如果使用的不是 中的路径匹配器,是默认的,需要注意 以下写法对应不一样

  • /a
  • /a/

以上对于新的匹配器来说是两个不同的路径。
 

六 跨域配置问题

问题:

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("*");
    }

 

 

 


 

 

 

 

https://www.leftso.com/article/1108.html

相关文章
升级环境说明目前项目使用的2.3.7版本(自己感觉还行,但是官方已经停止支持了。)Spring Boot 官方支持情况spring boot 官方支持情况官方在今年8月就终止了对2.3.x的版本...
Spring Boot 1.x升级到Spring Boot 2.0迁移指南
Spring Boot 2.1 新特性,已升级Spring 版本为5.1,支持servlet 4.0,支持Tomcat 9.0等等
Spring boot 1.x官方即将停止开发及维护Spring Boot 1.x EOL 2019年1月1日
Spring Boot 2.0 绑定properties属性资源文件 Spring Boot 2.0 读取properties配置文件值 Spring Boot 2.0获取properties配...
Spring Boot 2.0 有哪些新特性_Spring Boot 2.0新功能,在本文中,我们将探讨为Spring Boot 2.0计划的一些更改和功能。我们还会描述这些变化如何帮助我们提高...
spring boot 2.x设置静态资源缓存时间
Spring Boot 2.0 支持的Apache Camel 版本发布了_Apache Camel 2.22发布支持Spring Boot 2.0
spring boot整合Jersey2.x实现JAX-RS webservice
本文将介绍Spring Boot和HikariCP示例。HikariCP是快速,简单,可靠和生产就绪的JDBC连接池。在Spring Boot 2.0版本中,默认数据库池技术已从Tomcat P...
项目升级到springboot之后,参数校验的注解报错,经过与原项目对比,发现spring-boot-starter-web的依赖项已经去除了依赖原版会有如下: &lt;dependency&g...
前言    本教程主要讲解spring boot如何整合 spring data elasticsearch 实现elasticsearch检索引擎的整合使用
Spring Boot 2.0 Redis整合,通过spring boot 2.0整合Redis作为spring缓存框架的实现。
Spring Boot 2.0,Spring框架的Spring Boot 中的Spring Boot Actuator变化讲解。并且了解如何在Spring Boot 2.0中使用Actuator...
spring boot 2.0 security 5.0 整合,实现自定义表单登录。spring boot 2.0框架使用。