springboot 1.5.X 升級(jí)2.X踩坑記錄

升級(jí)SpringBoot 2.1.6RELEASE 目前修改點(diǎn)

1. org.springframework.security.oauth.config ClientDetailsServiceConfigurer 配置修改

org.springframework.security.oauth2 配置在此省略
ClientDetailsServiceConfigurer:這個(gè)configurer定義了客戶端細(xì)節(jié)服務(wù)修改 重點(diǎn)這里的.secret必須使用加密字符串(無論使用內(nèi)存 redis 數(shù)據(jù)庫 存放token令牌 )必須要加密校驗(yàn)

       @Override
         public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
             // @formatter:off
             clients.inMemory().withClient(CLIENT_ID)
                     .authorizedGrantTypes("password", "refresh_token")
                     .scopes("read", "write", "trust")
                     .resourceIds(RESOURCE_ID)
                     .secret(new BCryptPasswordEncoder().encode(Constant.SECURITY_SERVER))//這里重點(diǎn) 1.5.9版本的jar 無此校驗(yàn)  2.X 后 不加會(huì)Encoded password does not look like BCrypt
                     .accessTokenValiditySeconds(Math.toIntExact(TimeUnit.DAYS.toSeconds(30)))
                     .refreshTokenValiditySeconds(Math.toIntExact(TimeUnit.DAYS.toSeconds(30)));
             // @formatter:on
         }

2. controller 層單獨(dú)參數(shù)就是要默認(rèn)傳 eg: String param param不傳過不了框架 可用 @RequestParam(require=false)

3. 接口URL中不能出現(xiàn)雙反斜杠 (調(diào)查Spring security 5.X 修改了源碼)(調(diào)用接口自行檢查)

4. 日期默認(rèn)返回 UTC 標(biāo)準(zhǔn)格式 而不是1.X版本的long時(shí)間戳了

如果想返回long 時(shí)間戳 配置文件

spring.jackson.serialization.write-dates-as-timestamps = true 

但是 sql 不能使用 UNIX_TIMESTAMP 否則報(bào)錯(cuò) TIMESTAMP cannot Long 個(gè)人理解 轉(zhuǎn)兩次long 報(bào)錯(cuò)

5. 數(shù)據(jù)庫連接池默認(rèn)更新為目前口碑性能最強(qiáng)的HikariCP

----- Hikari 連接池配置詳細(xì)配置請(qǐng)?jiān)L問https://github.com/brettwooldridge/HikariCP

    // 目前配置信息如下(需要根據(jù)系統(tǒng)實(shí)際使用情況優(yōu)化)
    spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
    spring.datasource.type=com.zaxxer.hikari.HikariDataSource
    ## 最小空閑連接數(shù)量
    spring.datasource.hikari.minimum-idle=5
    ## 空閑連接存活最大時(shí)間,默認(rèn)600000(10分鐘)
    spring.datasource.hikari.idle-timeout=180000
    ## 連接池最大連接數(shù),默認(rèn)是10
    spring.datasource.hikari.maximum-pool-size=10
    ## 此屬性控制從池返回的連接的默認(rèn)自動(dòng)提交行為,默認(rèn)值:true
    spring.datasource.hikari.auto-commit=true
    ## 連接池母子
    spring.datasource.hikari.pool-name=MyHikariCP
    ## 此屬性控制池中連接的最長生命周期,值0表示無限生命周期,默認(rèn)1800000即30分鐘
    spring.datasource.hikari.max-lifetime=1800000
    ## 數(shù)據(jù)庫連接超時(shí)時(shí)間,默認(rèn)25秒,即25000 (目前pc web 和接口的超時(shí)時(shí)間)
    spring.datasource.hikari.connection-timeout=25000
    spring.datasource.hikari.connection-test-query=SELECT 1
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容