最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

若依框架升級(jí)SpringBoot3全過(guò)程

 更新時(shí)間:2026年01月05日 15:30:38   作者:兔子先生°  
文章主要介紹了在使用若依框架升級(jí)到Spring Boot 3.0過(guò)程中遇到的問(wèn)題及解決方法,包括修改pom.xml文件、調(diào)整Druid和Security配置、處理JavaEE到JakartaEE的遷移以及解決前端參數(shù)接收問(wèn)題,作者通過(guò)個(gè)人經(jīng)驗(yàn)分享,希望能幫助其他開(kāi)發(fā)者順利升級(jí)項(xiàng)目

前言

若依官網(wǎng)給出的修改步驟,自己在實(shí)際操作過(guò)程中發(fā)現(xiàn)有部分缺失,無(wú)法正常啟動(dòng)。在經(jīng)過(guò)網(wǎng)上查閱資料后進(jìn)行添加可以重啟升級(jí)。

注意

  • 先將所有的pom文件修改完成再刷新,否則會(huì)出現(xiàn)找不到依賴(lài)的錯(cuò)誤。
  • 如果出現(xiàn),繼續(xù)將所有pom文件的內(nèi)容修改好再刷新。

一、修改父項(xiàng)目pom.xml

<!-- java.version版本8更換為17 -->
<java.version>17</java.version>

<!-- spring-boot版本2.5.15更換為3.1.5 -->
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-dependencies</artifactId>
	<version>3.2.5</version>
	<type>pom</type>
	<scope>import</scope>
</dependency>
<!-- 阿里數(shù)據(jù)庫(kù)連接池修改boot-3 -->
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid-spring-boot-3-starter</artifactId>
    <version>1.2.21</version>
</dependency>

<!-- 新增四個(gè)配置依賴(lài) -->
<!-- Jaxb -->
<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.1</version>
</dependency>

<!-- servlet -->
<dependency>
    <groupId>jakarta.servlet</groupId>
    <artifactId>jakarta.servlet-api</artifactId>
    <version>6.0.0</version>
</dependency>

<!-- mybatis-plus -->
<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter</artifactId>
    <version>3.5.5</version>
</dependency>

<!-- mysql -->
<dependency>
    <groupId>com.mysql</groupId>
    <artifactId>mysql-connector-j</artifactId>
    <version>8.1.0</version>
</dependency>

二、修改ruoyi-admin/pom.xml文件mysql依賴(lài)

<!-- Mysql驅(qū)動(dòng)包 -->
<dependency>
	<groupId>com.mysql</groupId>
	<artifactId>mysql-connector-j</artifactId>
</dependency>

三、修改ruoyi-framework/pom.xml文件

<!-- 修改 驗(yàn)證碼 -->
<dependency>
	<groupId>pro.fessional</groupId>
	<artifactId>kaptcha</artifactId>
	<exclusions>
		<exclusion>
			<artifactId>servlet-api</artifactId>
			<groupId>jakarta.servlet</groupId>
		</exclusion>
	</exclusions>
</dependency>

<!-- 修改 阿里數(shù)據(jù)庫(kù)連接池 -->
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid-spring-boot-3-starter</artifactId>
</dependency>

四、修改ruoyi-common/pom.xml文件

<!-- 修改 servlet包 -->
<dependency>
	<groupId>jakarta.servlet</groupId>
	<artifactId>jakarta.servlet-api</artifactId>
</dependency>

<!-- 添加 mybatis-plus -->
<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>

<!-- 添加 mybatis-spring -->
<dependency>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis-spring</artifactId>
    <version>3.0.3</version>
</dependency>

五、修改ruoyi-generator/pom.xml文件

<!-- 修改 阿里數(shù)據(jù)庫(kù)連接池 -->
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid-spring-boot-3-starter</artifactId>
</dependency>

六、修改DruidConfig類(lèi)

將引入的Druid改為boot3

import com.alibaba.druid.spring.boot3.autoconfigure.DruidDataSourceBuilder;
import com.alibaba.druid.spring.boot3.autoconfigure.properties.DruidStatProperties;

七、修改SecurityConfig類(lèi)

package com.ruoyi.framework.config;

import com.ruoyi.framework.config.properties.PermitAllUrlProperties;
import com.ruoyi.framework.security.filter.JwtAuthenticationTokenFilter;
import com.ruoyi.framework.security.handle.AuthenticationEntryPointImpl;
import com.ruoyi.framework.security.handle.LogoutSuccessHandlerImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.ProviderManager;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.authentication.logout.LogoutFilter;
import org.springframework.web.filter.CorsFilter;

/**
 * spring security配置
 *
 * @author ruoyi
 */
@EnableMethodSecurity(securedEnabled = true)
@Configuration
public class SecurityConfig {
    /**
     * 自定義用戶(hù)認(rèn)證邏輯
     */
    @Autowired
    private UserDetailsService userDetailsService;

    /**
     * 認(rèn)證失敗處理類(lèi)
     */
    @Autowired
    private AuthenticationEntryPointImpl unauthorizedHandler;

    /**
     * 退出處理類(lèi)
     */
    @Autowired
    private LogoutSuccessHandlerImpl logoutSuccessHandler;

    /**
     * token認(rèn)證過(guò)濾器
     */
    @Autowired
    private JwtAuthenticationTokenFilter authenticationTokenFilter;

    /**
     * 跨域過(guò)濾器
     */
    @Autowired
    private CorsFilter corsFilter;

    /**
     * 允許匿名訪問(wèn)的地址
     */
    @Autowired
    private PermitAllUrlProperties permitAllUrl;

    /**
     * @return
     * @throws Exception
     */
    @Bean
    AuthenticationManager authenticationManager() {
        DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider();
        // 身份認(rèn)證接口
        daoAuthenticationProvider.setUserDetailsService(userDetailsService);
        daoAuthenticationProvider.setPasswordEncoder(bCryptPasswordEncoder());
        return new ProviderManager(daoAuthenticationProvider);
    }

    /**
     * anyRequest | 匹配所有請(qǐng)求路徑
     * access | SpringEl表達(dá)式結(jié)果為true時(shí)可以訪問(wèn)
     * anonymous | 匿名可以訪問(wèn)
     * denyAll | 用戶(hù)不能訪問(wèn)
     * fullyAuthenticated | 用戶(hù)完全認(rèn)證可以訪問(wèn)(非remember-me下自動(dòng)登錄)
     * hasAnyAuthority | 如果有參數(shù),參數(shù)表示權(quán)限,則其中任何一個(gè)權(quán)限可以訪問(wèn)
     * hasAnyRole | 如果有參數(shù),參數(shù)表示角色,則其中任何一個(gè)角色可以訪問(wèn)
     * hasAuthority | 如果有參數(shù),參數(shù)表示權(quán)限,則其權(quán)限可以訪問(wèn)
     * hasIpAddress | 如果有參數(shù),參數(shù)表示IP地址,如果用戶(hù)IP和參數(shù)匹配,則可以訪問(wèn)
     * hasRole | 如果有參數(shù),參數(shù)表示角色,則其角色可以訪問(wèn)
     * permitAll | 用戶(hù)可以任意訪問(wèn)
     * rememberMe | 允許通過(guò)remember-me登錄的用戶(hù)訪問(wèn)
     * authenticated | 用戶(hù)登錄后可訪問(wèn)
     */
    @Bean
    SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {
        return httpSecurity
                // CSRF禁用,因?yàn)椴皇褂胹ession
                .csrf(AbstractHttpConfigurer::disable)
                // 禁用HTTP響應(yīng)標(biāo)頭
                .headers(header -> header.cacheControl(HeadersConfigurer.CacheControlConfig::disable).frameOptions(HeadersConfigurer.FrameOptionsConfig::disable))
                // 認(rèn)證失敗處理類(lèi)
                .exceptionHandling(exception -> exception.authenticationEntryPoint(unauthorizedHandler))
                // 基于token,所以不需要session
                .sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
                // 注解標(biāo)記允許匿名訪問(wèn)的url
                .authorizeHttpRequests((requests) -> {
                    permitAllUrl.getUrls().forEach(url -> requests.requestMatchers(url).permitAll());
                    // 對(duì)于登錄login 注冊(cè)register 驗(yàn)證碼captchaImage 允許匿名訪問(wèn)
                    requests.requestMatchers("/login", "/register", "/captchaImage").permitAll()
                            // 靜態(tài)資源,可匿名訪問(wèn)
                            .requestMatchers(HttpMethod.GET, "/", "/*.html", "/**.html", "/**.css", "/**.js", "/profile/**").permitAll()
                            .requestMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/*/api-docs/**", "/druid/**").permitAll()
                            // 除上面外的所有請(qǐng)求全部需要鑒權(quán)認(rèn)證
                            .anyRequest().authenticated();
                })
                // 添加Logout filter
                .logout(logout -> logout.logoutUrl("/logout").logoutSuccessHandler(logoutSuccessHandler))
                // 添加JWT filter
                .addFilterBefore(authenticationTokenFilter, UsernamePasswordAuthenticationFilter.class)
                // 添加CORS filter
                .addFilterBefore(corsFilter, JwtAuthenticationTokenFilter.class)
                .addFilterBefore(corsFilter, LogoutFilter.class).build();
    }

    /**
     * 強(qiáng)散列哈希加密實(shí)現(xiàn)
     */
    @Bean
    public BCryptPasswordEncoder bCryptPasswordEncoder() {
        return new BCryptPasswordEncoder();
    }
}

八、Java EE轉(zhuǎn)Jakarta EE

Spring Boot 3.0將所有底層依賴(lài)項(xiàng)從Java EE遷移到了Jakarta EE,會(huì)對(duì)一些使用了Java EE的方法造成影響,需要進(jìn)行相應(yīng)的修改和調(diào)整

javax.annotation 替換成 jakarta.validation
javax.servlet    替換成 jakarta.servlet
javax.validation 替換成 jakarta.validation
#代碼生成模板controller.java.vm也需要換一下javax為jakarta

九、解決前端調(diào)用了使用@PathVariable接收參數(shù)的接口報(bào)錯(cuò)問(wèn)題

java.lang.IllegalArgumentException: Name for argument of type [java.lang.String] not specified, and parameter name information not available via reflection. Ensure that the compiler uses the ‘-parameters’ flag.

解決辦法

指定接收參數(shù)名,如

@PathVariable(“dictType”)或者@PathVariable(name = “dictType”)

// 調(diào)用這個(gè)接口會(huì)報(bào)錯(cuò)
@GetMapping(value = "/type/{dictType}")
public AjaxResult dictType(@PathVariable String dictType)
{
    List<SysDictData> data = dictTypeService.selectDictDataByType(dictType);
    if (StringUtils.isNull(data))
    {
        data = new ArrayList<SysDictData>();
    }
    return success(data);
}

// 修改之后
@GetMapping(value = "/type/{dictType}")
public AjaxResult dictType(@PathVariable("dictType") String dictType)
{
    List<SysDictData> data = dictTypeService.selectDictDataByType(dictType);
    if (StringUtils.isNull(data))
    {
        data = new ArrayList<SysDictData>();
    }
    return success(data);
}

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • java修改JFrame默認(rèn)字體方式

    java修改JFrame默認(rèn)字體方式

    這篇文章主要介紹了java修改JFrame默認(rèn)字體方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-11-11
  • Java?stream?sorted使用?Comparator?進(jìn)行多字段排序的方法

    Java?stream?sorted使用?Comparator?進(jìn)行多字段排序的方法

    這篇文章主要介紹了Java?stream?sorted使用?Comparator?進(jìn)行多字段排序,主要講解使用Java?Stream流排序器Comparator對(duì)List集合進(jìn)行多字段排序的方法,包括復(fù)雜實(shí)體對(duì)象多字段升降序排序方法,需要的朋友可以參考下
    2023-03-03
  • java中Map集合的常用方法總結(jié)大全

    java中Map集合的常用方法總結(jié)大全

    開(kāi)發(fā)中最常用的就是List集合和Map集合,Map集合是基于java核心類(lèi)java.util中的,下面這篇文章主要給大家總結(jié)介紹了關(guān)于java中Map集合的一些常用方法,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2024-01-01
  • mybatis的association傳遞參數(shù)問(wèn)題示例

    mybatis的association傳遞參數(shù)問(wèn)題示例

    這篇文章主要介紹了mybatis的association傳遞參數(shù)問(wèn)題,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-12-12
  • Spring為IOC容器注入Bean的五種方式詳解

    Spring為IOC容器注入Bean的五種方式詳解

    這篇文章主要介紹了Spring為IOC容器注入Bean的五種方式詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-10-10
  • 詳解MyBatisPlus如何實(shí)現(xiàn)分頁(yè)和查詢(xún)操作

    詳解MyBatisPlus如何實(shí)現(xiàn)分頁(yè)和查詢(xún)操作

    這篇文章主要為大家詳細(xì)介紹了MyBatisPlus是如何實(shí)現(xiàn)分頁(yè)和查詢(xún)操作的,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)有一定的幫助,需要的可以參考一下
    2022-05-05
  • Jenkins自動(dòng)構(gòu)建部署項(xiàng)目到遠(yuǎn)程服務(wù)器上的方法步驟

    Jenkins自動(dòng)構(gòu)建部署項(xiàng)目到遠(yuǎn)程服務(wù)器上的方法步驟

    這篇文章主要介紹了Jenkins自動(dòng)構(gòu)建部署項(xiàng)目到遠(yuǎn)程服務(wù)器上的方法步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-01-01
  • Spring Boot假死診斷實(shí)戰(zhàn)記錄

    Spring Boot假死診斷實(shí)戰(zhàn)記錄

    這篇文章主要給大家介紹了關(guān)于Spring Boot假死診斷的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Spring Boot具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-07-07
  • java開(kāi)發(fā)之Jdbc分頁(yè)源碼詳解

    java開(kāi)發(fā)之Jdbc分頁(yè)源碼詳解

    這篇文章主要介紹了java開(kāi)發(fā)之Jdb分頁(yè)源碼詳解,需要的朋友可以參考下
    2020-02-02
  • Spring AOP注解案例及基本原理詳解

    Spring AOP注解案例及基本原理詳解

    這篇文章主要介紹了Spring AOP注解案例及基本原理詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-06-06

最新評(píng)論

衡水市| 平远县| 慈利县| 莱州市| 保亭| 溆浦县| 深水埗区| 遵义市| 吉木乃县| 夹江县| 塘沽区| 吉安市| 临泽县| 屏东县| 微博| 河间市| 正阳县| 万州区| 尉犁县| 冀州市| 罗城| 富川| 临西县| 尚义县| 庆城县| 兰州市| 台东县| 梁河县| 盈江县| 苗栗市| 鹰潭市| 樟树市| 大洼县| 万荣县| 奇台县| 江油市| 湄潭县| 芦山县| 文昌市| 阜宁县| 曲周县|