【jasyt】Failed to bind properties under ‘spring.datasource.password‘ to java.lang.String: Reason:Fail

目录

问题描述

原因分析

解决方法

jar版本高版+新配置

参考文章


问题描述

        Description:
         
        Failed to bind properties under 'spring.datasource.password' to java.lang.String:
         
            Reason: Failed to bind properties under 'spring.datasource.password' to java.lang.String
         
        Action:
         
        Update your application's configuration
        描述:
         
        无法将“ spring.datasource.password”下的属性绑定到java.lang.String:
         
             原因:无法将“ spring.datasource.password”下的属性绑定到java.lang.String
         
        行动:
         
        更新您的应用程序的配置

原因分析

解决方法

步骤1:配置检查

#jasypt加密的密匙(写到启动参数里面)
jasypt:
  encryptor:
    password: qwert12345
    algorithm: PBEWithMD5AndDES

步骤2:更改pom引用jar版本

1)检查pom引用jar版本

<dependency>
    <groupId>com.github.ulisesbocchio</groupId>
    <artifactId>jasypt-spring-boot-starter</artifactId>
    <version>2.1.2</version>
</dependency>

2)配置无误test重新生成

3)代码

package com.god.demo;
         
import org.jasypt.encryption.StringEncryptor;
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
         
@SpringBootTest
class EncryptTests {
         
    private static final String ALGORITHM_INFO = "PBEWithMD5AndDES";         
    private static final String PASSWORD_INFO = "qwert12345";
         
    @Test
    void contextLoads() {
    }
         
    @Autowired
    StringEncryptor stringEncryptor;
         
    @Test
    public void encryptPwd() {
        StandardPBEStringEncryptor standardPBEStringEncryptor = new     StandardPBEStringEncryptor();
        //配置文件中配置如下的算法
        standardPBEStringEncryptor.setAlgorithm(ALGORITHM_INFO);
        //配置文件中配置的password
        standardPBEStringEncryptor.setPassword(PASSWORD_INFO);
        //要加密的文本
        String name = standardPBEStringEncryptor.encrypt("root");
        String password = standardPBEStringEncryptor.encrypt("root");
        String redisPassword = standardPBEStringEncryptor.encrypt("123456");
        //将加密的文本写到配置文件中
        System.out.println("name=" + name);
        System.out.println("password=" + password);
        System.out.println("redisPassword=" + redisPassword);
         
        //要解密的文本
        String name2 = standardPBEStringEncryptor.decrypt("FarrmxSQX5uwtH/NZRxy+g==");
        String password2 = standardPBEStringEncryptor.decrypt("vhiaYB1gl9zPj16yu7uMkA==");
        String redisPassword2 = standardPBEStringEncryptor.decrypt("ZII7UphhbVuJ8c3oxPUeyw==");
//解密后的文本
        System.out.println("name2=" + name2);
        System.out.println("password2=" + password2);
        System.out.println("redisPassword2=" + redisPassword2);         
    }
         
}

jar高版本+新配置

有位同学加了补充,本人亲测可用。依旧使用3.0.3版本的添加如下配置即可。

因为官方在 3.0.0 以后更改了加密算法,所以假如你不设置的话,使用网上的方法加密出来的密码启动就会报错。

 iv-generator-classname: org.jasypt.iv.NoIvGenerator

如图:

参考文章

原文链接:https://blog.csdn.net/libusi001/article/details/108465034

spring boot start 3.0.3 throw exception: 'spring.datasource.password' to java.lang.String · Issue #241 · ulisesbocchio/jasypt-spring-boot · GitHub

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值