当前位置: 首页> 科技> 名企 > springboot从2.7.2 升级到 3.3.0

springboot从2.7.2 升级到 3.3.0

时间:2025/9/14 1:11:24来源:https://blog.csdn.net/F_angT/article/details/139290718 浏览次数:2次

文章目录

    • 概要
    • 准备
    • 报错调整
    • 小结
    • 后记

概要

时代在进步,springboot已经来到了3.3.0 , 于是我们也打算升级下sbvadmin到3.3, jdk使用21的版本,下面是升级过程中碰到的一些问题,问题不大。
2.7.2 -> 3.3.0

准备

  • 下载jdk21,可以直接用idea,新建项目的时候下载

在这里插入图片描述
我下了zulu-21

或者 也可以到这里下载 https://learn.microsoft.com/en-us/java/openjdk/download#openjdk-21

  • 修改项目sdk
    这里能修改的都要修改掉
    在这里插入图片描述

  • 修改springboot的版本

    <parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>3.3.0</version><relativePath/></parent>

报错调整

import javax.validation.constraints.NotNull;

改为
import jakarta.validation.constraints.NotNull;

这里有很多类似的报错,把 javax改成jakarta就可以了


Cannot resolve method 'antMatchers' in 'IgnoredRequestConfigurer'

用 requestMatchers() 替代 antMatchers() 即可

Error processing condition on de.codecentric.boot.admin.client.config.SpringBootAdminClientAutoConfiguration.registrator

 <dependency><groupId>de.codecentric</groupId><artifactId>spring-boot-admin-starter-client</artifactId><version>3.2.3</version></dependency>
改成 3.2.3
https://github.com/codecentric/spring-boot-admin

Invalid value type for attribute 'factoryBeanObjectType': java.lang.String

改为<dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-spring-boot3-starter</artifactId><version>3.5.6</version></dependency>https://github.com/baomidou/mybatis-plus

Attempt to deserialize unauthorized class java.util.HashMap; add allowed class name patterns to the message converter or, if you trust the message originator, set environment variable 'SPRING_AMQP_DESERIALIZATION_TRUST_ALL' or system property 'spring.amqp.deserialization.trust.all' to true

Spring Boot 3 不再支持 application/x-java-serialized-object 格式的序列化传输,这是因为该格式与安全最佳实践不兼容,而且 Java 序列化机制存在安全隐患。

package com.sbvadmin.mailserver.config;import org.springframework.amqp.support.converter.DefaultClassMapper;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;@Configuration
public class RabbitMQConfig {@Beanpublic MessageConverter MessageConverter() {return new Jackson2JsonMessageConverter();}
}https://blog.csdn.net/m0_64694079/article/details/134935219   看评论

小结

搞定!

Spring Boot 3.3 正式发布,王炸级更新,应用启动速度直接起飞!

后记

jdk21的版本可以运行,但是我打包的时候一直提示我:

[INFO] --- maven-compiler-plugin:3.13.0:compile (default-compile) @ admin-common ---
[INFO] Recompiling the module because of changed source code.
[INFO] Compiling 6 source files with javac [debug parameters release 17] to target/classesFailed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.13.0:compile (default-compile) on project admin-common: Fatal error compiling: 无效的目标发行版: 21 -> [Help 1]

从报错来看应该是编译的时候用javac 的jdk17 ,但我没找到如何改成21的地方。于是我改成了17来编译,但还是报错。后来发现用鼠标直接点clean 和 package是没问题的,但用命令跑就不行

mvn -B -DskipTests clean package -P prod

于是google了下,找到解决方案:https://www.codejava.net/tools/maven/fix-error-invalid-target-release
其实跑下

mvn -v 

就能知道是,环境变量的问题。 这个问题算解决了。

不过Compiling 6 source files with javac [debug parameters release 17] to target/classes 这里的17我一直没改成功到21。这个问题后续再看吧

关键字:springboot从2.7.2 升级到 3.3.0

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: