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

news/2025/3/3 13:26:48/

前言

最近想着把大火的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.ppmy.cn/news/1576296.html

相关文章

深入剖析 OpenCV:全面掌握基础操作、图像处理算法与特征匹配

深入剖析 OpenCV&#xff1a;全面掌握基础操作、图像处理算法与特征匹配 一、引言二、OpenCV 的安装&#xff08;一&#xff09;使用 pip 安装&#xff08;二&#xff09;使用 Anaconda 安装 三、OpenCV 基础操作&#xff08;一&#xff09;图像的读取、显示与保存&#xff08;…

基于springboot+vue的线上考试系统的设计与实现

开发语言&#xff1a;Java框架&#xff1a;springbootJDK版本&#xff1a;JDK1.8服务器&#xff1a;tomcat7数据库&#xff1a;mysql 5.7&#xff08;一定要5.7版本&#xff09;数据库工具&#xff1a;Navicat11开发软件&#xff1a;eclipse/myeclipse/ideaMaven包&#xff1a;…

LLMR: Real-time Prompting of Interactive Worldsusing Large Language Models

LLMR-使用大型语言模型的交互式世界实时建模 ABSTRACT 我们提出了混合现实的大语言模型&#xff08;LLMR&#xff09;&#xff0c;一个使用LLM实时创建和修改交互式混合现实体验的框架。LLMR利用新颖的策略来解决理想训练数据稀缺的困难情况&#xff0c;或者设计目标需要综合内…

Python 面向对象编程-继承与多态

目录 继承与多态 静态语言 vs 动态语言 小结 继承与多态 在OOP程序设计中&#xff0c;当我们定义一个class的时候&#xff0c;可以从某个现有的class继承&#xff0c;新的class称为子类&#xff08;Subclass&#xff09;&#xff0c;而被继承的class称为基类、父类或超类&a…

CentOS环境安装Docker

CentOS环境安装Docker 1.1 在线安装Docker 参考官方文档安装&#xff1a;https://docs.docker.com/engine/install/centos/ 1、更新yum yum update2、安装工具包 sudo yum install -y yum-utils3、 设置镜像源 sudo yum-config-manager --add-repo https://download.docke…

【2025年2月28日稳定版】小米路由器4C刷机Immortalwrt 23.05.4系统搭载mentohust 0.3.1插件全记录

小米路由器4C刷机Immortalwrt系统搭载mentohust插件全记录 首先将路由器按住后面的reset&#xff0c;用一个针插进去然后等待5s左右&#xff0c;松开&#xff0c;即可重置路由器。 然后要用物理网线物理连接路由器Lan口和电脑&#xff0c;并将路由器WAN口连接至网口。确保电脑…

【推荐项目】023-游泳俱乐部管理系统

023 游泳俱乐部管理系统 游泳俱乐部管理系统概述 前端技术框架&#xff1a; 我们优雅地采用了Vue.js作为游泳俱乐部管理系统的前端基础框架。Vue.js以其轻盈、高效和易于上手的特点&#xff0c;为我们的用户界面带来了极致的流畅性和响应速度。通过Vue.js&#xff0c;我们为…

Ubuntu20.04安装Redis

目录 切换到root用户 使用 apt install redis 安装redis 修改配置文件 ​编辑 重新启动服务器 使用Redis客户端连接服务器 切换到root用户 如果没有切换到root用户的&#xff0c;切换到root用户。 使用 apt install redis 安装redis 遇到y/n直接y即可。 redis安装好之…