当前位置: 首页 > news >正文

SpringBoot 2.x 升 3.x 避坑指南:企业级项目的实战问题与解决方案

spring boot 3.4.8 对应spring-cloud.version 多少适配

解决方法:

<dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-alibaba-dependencies</artifactId><version>${spring-cloud-alibaba.version}</version><type>pom</type><scope>import</scope>
</dependency>
<spring-cloud-alibaba.version>2023.0.1.0</spring-cloud-alibaba.version>

import javax.validation.Constraint; import javax.validation.Payload; 怎么找不到这两个包

解决方法

删除:

<!-- Bean Validation API(包含 javax.validation 相关接口) -->
<dependency><groupId>javax.validation</groupId><artifactId>validation-api</artifactId>
</dependency><!-- 可选:添加Hibernate Validator作为运行时实现(如果需要实际校验功能) -->
<dependency><groupId>org.hibernate.validator</groupId><artifactId>hibernate-validator</artifactId>
</dependency>

替换成:

<!-- Jakarta Bean Validation API -->
<dependency><groupId>jakarta.validation</groupId><artifactId>jakarta.validation-api</artifactId><version>3.0.2</version> <!-- 对应JSR-380,适用于Jakarta EE 9+ -->
</dependency><!-- 运行时实现 -->
<dependency><groupId>org.hibernate.validator</groupId><artifactId>hibernate-validator</artifactId><version>7.0.5.Final</version>
</dependency>

无法访问jakarta.servlet.http.HttpServletRequest

解决方法:

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><!-- 无需指定版本,由 spring-boot-starter-parent 管理 -->
</dependency>

程序包org.aspectj.lang不存在 java版本是17 如何解决这个问题

解决方法

<dependency><groupId>org.aspectj</groupId><artifactId>aspectjrt</artifactId><version>1.9.20.1</version> <!-- 使用最新稳定版本 -->
</dependency>
<dependency><groupId>org.aspectj</groupId><artifactId>aspectjweaver</artifactId><version>1.9.20.1</version>
</dependency>

httpSecurity.antMatchers() 找不到符号

解决方法

// 旧写法
httpSecurity.antMatchers("/public/**").permitAll().antMatchers("/admin/**").hasRole("ADMIN");// 新写法
httpSecurity.requestMatchers("/public/**").permitAll().requestMatchers("/admin/**").hasRole("ADMIN");

Java 17 应该选用flowable 版本多少

Flowable 6.8.x 及以上版本

问题

Springboot 版本升级为3.x 后,启动应用程序 报错 Application run failed java.lang.IllegalStateException: The following classes could not be excluded because they are not auto-configuration classes: - com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure

解决方法

<dependency><groupId>com.alibaba</groupId><artifactId>druid-spring-boot-3-starter</artifactId><version>1.2.20</version> <!-- 使用最新兼容版本 -->
</dependency>

问题

Springboot 版本升级为3.x 后,启动应用程序 报错 Invalid bean definition with name ‘shopProductMapper’ defined in file [D:\work\project\gitee-github\cherry-cloud\cherry-modules\cherry-modules-use\target\classes\com\ruoyi\use\mapper\ShopProductMapper.class]: Invalid value type for attribute ‘factoryBeanObjectType’: java.lang.String

解决方法:

<!-- MyBatis 与 Spring Boot 3.x 兼容的版本 -->
<dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>3.0.3</version> <!-- 至少 3.0.0 以上版本 -->
</dependency>

问题

<dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper-spring-boot-starter</artifactId></dependency>        与 Spring Boot 3.x 兼容的版本  多少?

解决方法:

   <!-- Pagehelper --><dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper-spring-boot-starter</artifactId><exclusions><exclusion><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId></exclusion></exclusions></dependency><!-- MyBatis 与 Spring Boot 3.x 兼容的版本 --><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>3.0.3</version> <!-- 至少 3.0.0 以上版本 --></dependency>

Swagger2 和 Swagger3 有什么区别 和联系

  • 若使用 Spring Boot 2.3.x 及以下:可使用 Springfox Swagger2(2.9.x)。
  • 若使用 Spring Boot 2.4.x - 2.7.x:推荐 SpringDoc-OpenAPI 1.x(替代 Swagger2,支持 OpenAPI 3.0)。
  • 若使用 Spring Boot 3.x 及以上:必须使用 SpringDoc-OpenAPI 2.x(完全兼容新特性)。

若使用 Spring Boot 3.x 及以上:必须使用 SpringDoc-OpenAPI 2.x(完全兼容新特性) maven 依赖怎么写

解决办法

<!-- SpringDoc OpenAPI 核心依赖 -->
<dependency><groupId>org.springdoc</groupId><artifactId>springdoc-openapi-starter-webmvc-ui</artifactId><version>2.1.0</version> <!-- 最新稳定版,支持 Spring Boot 3.x -->
</dependency>
  • Swagger UI 界面(访问路径:http://localhost:8080/swagger-ui/index.html

问题

import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; 如何改成 springdoc-openapi-starter-webmvc-ui 2.1.0 符合的注解

解决方法:

旧注解 (Swagger 2)新注解 (OpenAPI 3)说明
@Api@Tag用于描述控制器类
@ApiOperation@Operation用于描述接口方法
@ApiImplicitParam@Parameter用于描述请求参数
@ApiImplicitParams@Parameters用于包含多个@Parameter
  1. 其他常用注解替换:
  • @ApiParam@Parameter(用于方法参数上)
  • @ApiResponse@ApiResponse(包路径变为io.swagger.v3.oas.annotations.responses
  • @ApiResponses@ApiResponses(包路径变为io.swagger.v3.oas.annotations.responses
  • @ApiModel@Schema(用于描述实体类)
  • @ApiModelProperty@Schema(用于描述实体类属性)

问题

Non-resolvable import POM: Failure to find org.springframework.cloud:spring-cloud-dependencies:pom:2023.0.1.2 in https://maven.aliyun.com/repository/public was cached in the local repository, resolution will not be reattempted until the update interval of public has elapsed or updates are forced @ line 51, column 25 -> [Help 2] [ERROR] ‘dependencies.dependency.version’ for org.springframework.cloud:spring-cloud-starter-bootstrap:jar is missing. 如何解决

解决方法

        <spring-cloud.version>2023.0.1</spring-cloud.version><spring-cloud-alibaba.version>2023.0.1.0</spring-cloud-alibaba.version><!-- SpringCloud 微服务 --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><scope>import</scope></dependency><!-- SpringCloud Alibaba 微服务 --><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-alibaba-dependencies</artifactId><version>${spring-cloud-alibaba.version}</version><type>pom</type><scope>import</scope></dependency>

问题

Application run failed java.lang.IllegalStateException: java.lang.NoClassDefFoundError: io/seata/rm/fence/SpringFenceConfig

解决方法

<dependency><groupId>io.seata</groupId><artifactId>seata-spring-boot-starter</artifactId><version>1.6.1</version> <!-- 使用 1.4.0+ 版本 -->
</dependency><!-- 如果需要分布式事务栅栏功能,可能还需要 -->
<dependency><groupId>io.seata</groupId><artifactId>seata-rm-fence</artifactId><version>1.6.1</version>
</dependency>

问题

Description: Field storageClient in com.ruoyi.file.service.FastDfsSysFileServiceImpl required a bean of type ‘com.github.tobato.fastdfs.service.FastFileStorageClient’ that could not be found. 这个问题如何解决

解决方法

   @Autowired(required=false)private FastFileStorageClient storageClient;

问题

int org.springframework.web.reactive.function.client.ClientResponse.rawStatusCode()’ 报这个如何解决?

解决方法

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-webflux</artifactId><version>3.1.5</version> <!-- 使用最新稳定版 -->
</dependency>
http://www.dtcms.com/a/313448.html

相关文章:

  • Celery-分布式任务队列
  • MySQL深度理解-MySQL锁机制
  • 数据结构学习(day01)
  • 第八章:进入Redis的SET的核心
  • Android系统模块编译调试与Ninja使用指南
  • 【数据分享】各省粮食外贸依存度、粮食波动率等粮食相关数据合集(2011-2022)(获取方式看文末)
  • 【MATLAB】(六)多项式的创建与四则运算
  • python的高校奖助学金系统
  • 23 Active Directory攻击与防护策略解析
  • 编译旧版本的electron内核
  • SpringBoot之整合MyBatisPlus
  • Nvidia Orin DK 刷机CUDA TensorRT+硬盘扩容+ROS+Realsense+OpenCV+Ollama+Yolo11 一站式解决方案
  • 从“配置地狱”到“云端乐园”——Nacos 如何成为分布式微服务配置中心的“定海神针”
  • 数组和指针的关系
  • 操作系统——读者写者问题
  • KNX协议介绍
  • Nvidia Orin + RealSense D435i 与3D地图实现导航
  • Ubuntu系统VScode实现opencv(c++)视频的处理与保存
  • [硬件电路-129]:模拟电路 - 继电器的工作原理、关键指标、常用芯片与管脚定义
  • SpringAI的使用
  • Socket编程——TCP协议
  • 从一到无穷大 #51:突破阿姆达尔定律:COZ因果剖析与串行优化八法
  • Java学习第一百零一部分——网关(Gateway)
  • java测试题(ssm框架)
  • 02.Redis 安装
  • MPLS 静态LSP
  • TV电视版软件集合分享
  • 深入理解Java并发编程:原理、实战与最佳实践
  • Redis 7 中的 Set 和 Zset 使用
  • 基于transformer的目标检测——匈牙利匹配算法