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

news/2024/10/15 7:15:22/

从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/news/1539324.html

相关文章

SeamlessUI功能验证流程

停止服务 systemctl stop aispeech-engine-wrapper systemctl stop dialog-domain-handlers systemctl stop dialog-engine systemctl stop dialog-audio-service然后是修改配置文件&#xff0c;打开配置文件中的SeamlessUI的开关 /etc/dialog-engine/features/toggles.json …

linux线程 | 线程的控制(一)

前言&#xff1a;本节内容为线程的控制。在本篇文章中&#xff0c; 博主不仅将会带友友们认识接口&#xff0c; 使用接口。 而且也会剖析底层&#xff0c;带领友友们理解线程的底层原理。 相信友友们学完本节内容&#xff0c; 一定会对线程的控制有一个很好的把握。 那么&#…

Springboot --- 使用国内的 AI 大模型 对话

尝试使用 国内给出的 AI 大模型做出一个 可以和 AI 对话的 网站出来 使用 智普AI 只能 在控制台中输出 对应的信息 不如就做一个 maven 的 项目调用对应的API 智谱AI开放平台 <dependency><groupId>cn.bigmodel.openapi</groupId><artifactId>oapi-j…

10 分钟使用豆包 MarsCode 帮我搭建一套后台管理系统

以下是「 豆包MarsCode 体验官」优秀文章&#xff0c;作者把梦想揉碎。 十分钟使用豆包 MarsCode 搭建后台管理项目 在这个快节奏的时代&#xff0c;开发者们总是希望能够快速、高效地完成项目的搭建与开发工作。无论是初创企业还是大型公司&#xff0c;后台管理系统都是必不可…

链接伪类(:hover)CSS背景图片有闪动BUG的解决方法 vue3

现象&#xff1a; hover时候&#xff0c;图片还没加载出来&#xff0c;导致边框闪烁 在Vue 3中&#xff0c;如果你遇到了使用伪类(:hover)时背景图片出现闪烁的问题&#xff0c;可能是由于浏览器的渲染机制导致的。解决这个问题的方法可能包括&#xff1a; 使用background-pos…

忘记 MySQL 密码后如何修改密码的详细步骤指南

引言 在日常使用 MySQL 数据库的过程中,忘记 MySQL 密码是一种常见的情况。当我们无法通过已有的密码登录 MySQL 时,需要通过某些技巧和方法来重置密码。本文将详细介绍在各种操作系统环境下,忘记 MySQL 密码后的解决方案,帮助用户快速恢复 MySQL 数据库的访问权限。 目录…

C#中判断的应用说明二(switch语句)

一.判断的定义说明 判断结构要求程序员指定一个或多个要评估或测试的条件&#xff0c;以及条件为真时要执行的语句&#xff08;必需的&#xff09;和条件为假时要执行的语句&#xff08;可选的&#xff09;。下面是大多数编程语言中典型的判断结构的一般形式&#xff1a; 二.判…

继承、Lambda、Objective-C和Swift

继承 东风系列导弹是镇国神器。东风41不是突然就造出来的&#xff0c;之前有很多种东风xx导弹&#xff0c;每种导弹都有自己的独特之处&#xff0c;相同之处都具备导弹基本特点。很多工厂有量产磨具的生产线&#xff0c;盖房子就图纸&#xff0c;建筑设计建设都有参考&#xff…