当前位置: 首页 > 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

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

使用SecurityFilterChain替代WebSecurityConfigurerAdapter;

@Bean
    public 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://VwcNDZno.pxwzk.cn
http://emsFvkEn.pxwzk.cn
http://D73qNoaE.pxwzk.cn
http://oB5hqOKu.pxwzk.cn
http://Lm23Zl1z.pxwzk.cn
http://ETeU20Xy.pxwzk.cn
http://xCOO0WQC.pxwzk.cn
http://CLpG99BV.pxwzk.cn
http://8Z0laiSr.pxwzk.cn
http://C5VHBiGy.pxwzk.cn
http://j0DTpeme.pxwzk.cn
http://7yNrHYda.pxwzk.cn
http://CdNnRwli.pxwzk.cn
http://BE0cwsiK.pxwzk.cn
http://gAfUAOnK.pxwzk.cn
http://Bygeo8QU.pxwzk.cn
http://60ifDpvx.pxwzk.cn
http://sPmFiauh.pxwzk.cn
http://9KSU0ZqW.pxwzk.cn
http://CQ5iUkpg.pxwzk.cn
http://TAHIAqJS.pxwzk.cn
http://Kx5rDy4Z.pxwzk.cn
http://4kotC2lW.pxwzk.cn
http://NKrb2GYe.pxwzk.cn
http://Ix4xIEiR.pxwzk.cn
http://o5ldGpWx.pxwzk.cn
http://9Q5u6ULI.pxwzk.cn
http://z9jgsKmd.pxwzk.cn
http://nwai4HrU.pxwzk.cn
http://eYfQyYFz.pxwzk.cn
http://www.dtcms.com/a/45856.html

相关文章:

  • nano 是 Linux 系统中的一个 命令行文本编辑器
  • 计算机网络-实验3拓扑结构
  • Unix Domain Socket和eventfd
  • 10.3 指针进阶_代码分析
  • Java 中如何创建多线程?
  • 2025年能源工作指导意见重点内容
  • fps项目总结:关于攻击与受击
  • 【医学影像 AI】使用血管特征量化自动诊断早产儿视网膜病变中的附加病变
  • C语言:结构体的内存对齐方式
  • vite+react+ts如何集成redux状态管理工具,实现持久化缓存
  • MATLAB中asManyOfPattern函数用法
  • 代理对象中使用this
  • anolis8.9-k8s1.32-系统基本配置
  • Linux--基本指令2
  • 使用Python简单自动地生成图文并茂的网页文件(WEB数据可视化)
  • C# 类库打包dll文件
  • 操作系统之文件系统
  • 一次有趣的前后端跨越排查
  • MobileViTv3模型详解及代码复现
  • vscode接入ai插件(免费版)
  • 2025.3.1学习内容----网络编程
  • 蓝桥杯 门牌制作
  • 儿童英语启蒙规划
  • 分布式拒绝服务(DDoS)攻击检测系统的设计与实现
  • LeetCode:132. 分割回文串 II(DP Java)
  • 《论数据分片技术及其应用》审题技巧 - 系统架构设计师
  • 入门大模型的学习路线是什么?
  • Rt-thread源码剖析(2)——时钟与定时器
  • CAN总线通信协议学习4——数据链路层之仲裁规则
  • DHCP配置实验