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

【重构小程序】升级JDK1.8、SpringBoot2.x 到JDK17、Springboot 3.x(一)

前言

最近想着把大火的deepseek 迁移到小程序里,基于刷题小程序的数据库做一个RAG应用,来进一步扩展答案解析,帮助用户解答相关问题。但是由于之前做的项目都要老了,并不支持spring 的AI模块,因此,我打算先升级一下系统。

一、升级JDK 1.8 到 JDK 17

1、首先从官网上下载一个JDK17的包,windows系统可能有这两种包(压缩包和安装包)

直接下载压缩包,放在一个中文目录下,然后修改环境变量。 

 然后看一下java版本 java --version 是否修改成功。

 修改项目中的设置 如下

 

二、升级Springboot 2.x 到 Springboot 3.x  

 修改pom文件

    <parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>3.2.0</version><relativePath/></parent>
    <properties><java.version>17</java.version></properties>

这里面需要注意的东西还挺多的

1、javax.servlet.*相关的类找不到,需要切换依赖为jakarta.servlet。修改javax.servlet.*为jakarta.servlet.*。

		<!--jakarta.servlet start --><dependency><groupId>jakarta.servlet</groupId><artifactId>jakarta.servlet-api</artifactId></dependency><!--jakarta.servlet end -->

 2.、mybatis-plus-boot-starter

		<!-- mybatis-plus start--><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-spring-boot3-starter</artifactId><version>3.5.5</version></dependency><!-- mybatis-plus end-->

 3、redis

spring.data.redis.host=127.0.0.1
#Redis服务器连接端口
spring.data.redis.port=6379
#连接池最大连接数(使用负值表示没有限制)
spring.data.redis.lettuce.pool.max-active=20
#连接池最大阻塞等待时间(使用负值表示没有限制)
spring.data.redis.lettuce.pool.max-wait=-1
#连接池中的最大空闲连接
spring.data.redis.lettuce.pool.max-idle=5
#连接池中的最小空闲连接
spring.data.redis.lettuce.pool.min-idle=0
#连接超时时间(毫秒)
spring.data.redis.timeout=1800000

4、commons-pool2

Spring Boot 的 spring-boot-starter-data-redis 依赖了 Lettuce 作为 Redis 客户端。

Lettuce 依赖于 commons-pool2 来实现连接池功能。

因此我们也需要更新一下commons-pool2的版本。

        <dependency><groupId>org.apache.commons</groupId><artifactId>commons-pool2</artifactId><version>2.11.1</version></dependency>

4、Spring-Security 

咋WebSecurityConfig显示的注册authenticationManager为一个Bean

    @Beanpublic AuthenticationManager authenticationManager(AuthenticationConfiguration config) throws Exception {return config.getAuthenticationManager();}

使用SecurityFilterChain替代WebSecurityConfigurerAdapter;

@Beanpublic SecurityFilterChain securityFilterChain(HttpSecurity http,CustomizeAuthenticationEntryPoint customizeAuthenticationEntryPoint,CustomizeAccessDeniedHandler customizeAccessDeniedHandler) throws Exception {http.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED)).authenticationProvider(thirdLoginAuthenticationProvider).authorizeHttpRequests(authorize -> authorize.requestMatchers("/swagger-resources/configuration/ui","/swagger-resources","/swagger-resources/configuration/security","/swagger-ui.html",).permitAll().anyRequest().authenticated()).exceptionHandling(exception -> exception.accessDeniedHandler(customizeAccessDeniedHandler).authenticationEntryPoint(customizeAuthenticationEntryPoint)).cors(cors -> cors.configure(http)).csrf(csrf -> csrf.disable());return http.build();}

Spring-Security 6.x的版本中,对于session的管理也发生了一些变化,需要手动将 SecurityContext 保存到 HttpSession 中。

        HttpSession session = request.getSession();session.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY, SecurityContextHolder.getContext());

修改到这里位置,就可以启动项目了。

http://www.lryc.cn/news/545451.html

相关文章:

  • 功能丰富的自动化任务软件zTasker_2.1.0_绿色版_屏蔽强制更新闪退
  • _ 为什么在python中可以当变量名
  • Java 9 到 Java 21 新特性全解析:从语法简化到API增强
  • LeeCode题库第三十九题
  • 卫星网络仿真平台:IPLOOK赋能空天地一体化通信新生态​
  • (十一)基于vue3+mapbox-GL实现模拟高德实时导航轨迹播放
  • 计算机面试项目经历描述技巧
  • 132. 分割回文串 II
  • 【每日学点HarmonyOS Next知识】全局调整字体、h5选择框无法取消选中、margin不生效、Length转换为具体值、Prop和link比较
  • 九、Spring Boot:自动配置原理
  • (动态规划 最长重复子数组)leetcode 718
  • SFP+(Enhanced Small Form-factor Pluggable)详解
  • 计算机毕业设计Hadoop+Spark+DeepSeek-R1大模型音乐推荐系统 音乐数据分析 音乐可视化 音乐爬虫 知识图谱 大数据毕业设计
  • Deepseek对ChatGPT的冲击?
  • 【Python 初级函数详解】—— 参数沙漠与作用域丛林的求生指南
  • 极客大学 java 进阶训练营怎么样,图文详解
  • 机器人学习模拟框架 robosuite (3) 机器人控制代码示例
  • 玩转python: 几个案例-掌握贪心算法
  • 腾讯集团软件开发-后台开发方向内推
  • 哈希碰撞攻防战——深入浅出Map/Set的底层实现
  • 深度解析Ant Design Pro 6开发实践
  • 用大白话解释基础框架Spring Boot——像“装修套餐”一样简单
  • 第十三届蓝桥杯大赛软件赛决赛C/C++ 大学 B 组
  • java后端开发day25--阶段项目(二)
  • 岚图汽车2月销售8013辆,岚图知音硬核引领智能出行
  • 【CSS—前端快速入门】CSS 常用样式
  • 【软考-架构】1.3、磁盘-输入输出技术-总线
  • Linux软连接与时区日期
  • (十)Mapbox GL JS 中点击 Marker 时获取与该 Marker 相关的自定义数据的解决办法
  • PyCharm怎么集成DeepSeek