解决jasypt failed to bind properties

failed to bind properties under spring.datasource.druid.password' to java.lang.String

jasypt默认更改了算法,如果不指定那么会报错:failed to bind properties under spring.datasource.druid.password' to java.lang.String

解决办法:

①把版本降到2.x
②指定加密方法,如下
algorithm: PBEWithMD5AndDES
iv-generator-classname: org.jasypt.iv.NoIvGenerator

配置过程

1.导包



    com.github.ulisesbocchio
    jasypt-spring-boot-starter
    3.0.3

2.配置yml

2.1.关于jasypt部分的配置:

jasypt:
  encryptor:
      #加解密的密码
    password: atpingan
    #jasypt默认更改了算法,如果不指定那么会报错:failed to bind properties under 'spring.datasource.druid.password' to java.lang.String
    #解决办法:①把版本降到2.x②指定加密方法,如下
    algorithm: PBEWithMD5AndDES
    iv-generator-classname: org.jasypt.iv.NoIvGenerator

2.2.关于加密部分的配置:

spring:
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    druid:
      driver-class-name: com.mysql.cj.jdbc.Driver
      url: jdbc:mysql://192.168.200.141:3306/mysql?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai
      #加密密码atpingan
      username: ENC(kud5ZnaMJYve284geT0ITw==)
      password: ENC(0CwfH4246HP22Rv74d/ZPw==)

其中ENC()是默认加密法的固定配置,后面会讲自定义加密法

2.3.重点:(2.x和3.x的区别)

jasypt默认更改了算法,如果不指定那么会报错:failed to bind properties under spring.datasource.druid.password' to java.lang.String

解决办法:

①把版本降到2.x
②指定加密方法,如下
algorithm: PBEWithMD5AndDES
iv-generator-classname: org.jasypt.iv.NoIvGenerator

你可能感兴趣的