springboot从2.7.2 升级到 3.3.0

概要

时代在进步,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 {

    @Bean
    public 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/classes

Failed 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。这个问题后续再看吧

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

F_angT

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值