从2.x到3.x:Spring Boot升级遇到的问题!

embedded/2024/10/18 18:28:06/

从2.x到3.x:Spring Boot升级遇到的问题!

  • 1.关于redis报错
  • 2.关于servlet报错
  • 2.关于Spring Security报错

报错内容采集

1.关于redis报错

报错内容:Property ‘spring.redis.host’ is Deprecated: Use ‘spring.data.redis.host’ instead.”、“Property ‘spring.redis.password’ is Deprecated: Use ‘spring.data.redis.password’ instead.

把“spring.redis”替换成“spring.data.redis”即可。

在application.yml文件里

javascript">spring.data.redis.host=127.0.0.1
spring.data.redis.port=6379

在application.yml文件里

javascript"> web:resources:add-mappings: falsedata:redis:host: 127.0.0.1port: 6379
javascript">datasource:// druid:  去除druidurl: jdbc:mysql://127.0.0.1:3306/supervision_dev?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&failOverReadOnly=false&serverTimezone=GMT%2B8&allowMultiQueries=trueusername: rootpassword: admin

2.关于servlet报错

报错内容:The import javax.servlet cannot be resolved

javax.servlet 替换为 jakarta.servlet

如:

javascript">import jakarta.servlet.ReadListener;
import jakarta.servlet.ServletInputStream;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletRequestWrapper;

2.关于Spring Security报错

报错内容:找不到类org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter

几乎是大家都会用去的WebSecurityConfigurerAdapter被删除了,原先继承这个的类现在无需继承任何类,只需要带上@Configuration注解。
原本配置WebSecurity和HttpSecurity的configure方法变为普通的@Bean方法,分别返回WebSecurityCustomizer和SecurityFilterChain。
原先的方法authorizeRequests变为authorizeHttpRequests、方法antMatchers变为requestMatchers。

修改自Spring Security官方博客的例子:

以前的写法

javascript">@Configuration
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {@Overridepublic void configure(WebSecurity web) {web.ignoring().antMatchers("/ignore1", "/ignore2");}@Overrideprotected void configure(HttpSecurity http) throws Exception {http.authorizeRequests().anyRequest().authenticated().and().httpBasic(withDefaults());}
}

现在的写法

javascript">@Configuration
// 不再继承于WebSecurityConfigurerAdapter
public class SecurityConfiguration {@Beanpublic WebSecurityCustomizer webSecurityCustomizer() {// WebSecurityCustomizer是一个类似于Consumer<WebSecurity>的接口,函数接受一个WebSecurity类型的变量,无返回值// 此处使用lambda实现WebSecurityCustomizer接口,web变量的类型WebSecurity,箭头后面可以对其进行操作// 使用requestMatchers()代替antMatchers()return (web) -> web.ignoring().requestMatchers("/ignore1", "/ignore2");}@Beanpublic SecurityFilterChain filterChain(HttpSecurity http) throws Exception {http//使用authorizeHttpRequests()代替authorizeRequests().authorizeHttpRequests((authz) -> authz//这种写法被称为Lambda DSL,代替原来的and()链式操作.anyRequest().authenticated()).httpBasic(withDefaults());// 需要进行build(),返回SecurityFilterChainreturn http.build();}
}

http://www.ppmy.cn/embedded/128528.html

相关文章

《15分钟轻松学Go》教程目录

在AI快速发展的时代&#xff0c;学习Go语言依然很有用。Go语言擅长处理高并发任务&#xff0c;也就是说可以同时处理很多请求&#xff0c;这对于需要快速响应的AI服务非常重要。另外&#xff0c;Go适合用来处理和传输大量数据&#xff0c;非常适合机器学习模型的数据预处理。 …

vue3中使用工具实现的打印功能总结

好记性不如烂笔头&#xff0c;如果不记录下来转眼就忘 本文只介绍这两种打印工具&#xff1a; print-jsvue3-print-nb 本次只因为需求更改为每页添加页眉而从 print-js 改为 vue3-print-nb 适用场景 print.js&#xff1a; 适合只有第一页有页眉&#xff0c;其他页没有的。…

Debezium系列之:实时从TDengine数据库采集数据到Kafka Topic

Debezium系列之:实时从TDengine数据库采集数据到Kafka Topic 一、认识TDengine二、TDengine Kafka Connector三、什么是 Kafka Connect?四、前置条件五、安装 TDengine Connector 插件六、启动 Kafka七、验证 kafka Connect 是否启动成功八、TDengine Source Connector 的使用…

【PCB】ADAS

1、布局设计 1.1.布局基本原则 1、元器件距离板边距离大于2mm,测试点距离板边大于3mm&#xff0c;BGA与晶体等易裂器件距离板边大于10mm 2、优先放置与结构关系密切的元器件&#xff0c;例如插件、开关等。其次规划好禁布区域及金边位置 3、高个电容、大电感、标贴连接器、BGA…

DOIP协议介绍2-Diagnostic power mode information request (0x4003)消息

DOIP&#xff08;Diagnostic communication over Internet Protocol&#xff09;是基于以太网的通讯协议&#xff0c;用于对UDS协议的数据进行传输&#xff0c;规范于ISO13400标准。DOIP的Type&#xff1a;Diagnostic power mode information request&#xff08;0x4003&#x…

【深度学习】阿里云GPU服务器免费试用3月

【深度学习】阿里云GPU服务器免费试用3月 1.活动页面2.选择交互式建模PAI-DSW3.开通 PAI 并创建默认工作空间4.前往默认工作空间5.创建交互式建模&#xff08;DSW&#xff09;实例 1.活动页面 阿里云免费使用活动页面 2.选择交互式建模PAI-DSW 支持抵扣PAI-DSW入门机型计算用量…

嵌入式职业规划

嵌入式职业规划 在嵌入式的软件开发中&#xff0c;可以分为&#xff1a; 嵌入式MCU软件开发工程师&#xff1b; 嵌入式Linux底层&#xff08;BSP&#xff09;软件开发工程师&#xff1b; 嵌入式Linux应用开发工程师&#xff1b; 嵌入式FPGA算法开发工程师 对于前两个阶段 …

GoFrame学习笔记

官方地址&#xff1a;https://goframe.org/display/gf 视频地址&#xff1a; https://www.bilibili.com/video/BV1Uu4y1u7kX/?vd_source707ec8983cc32e6e065d5496a7f79ee6 一、下载与安装 https://github.com/gogf/gf/releases 在系统变量的Path里设置一个GoFrame的安装目录点…