从字符串转换为 GuardedString 时,Spring Boot 中属性的自定义数据绑定问题

问题描述

我正在使用 Spring Boot 2.45,并且需要将从属性文件中获取的一些凭据保存为 GuardedString,因为它更安全。虽然自定义数据绑定适用于我的其他实例,但它无法将 String 转换为 GuardedString。这是我正在使用的转换器代码

import org.identityconnectors.common.security.GuardedString;
import org.springframework.boot.context.properties.ConfigurationPropertiesBinding;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

@Component
@ConfigurationPropertiesBinding
public class GuardedStringConverter implements Converter<String,GuardedString>{
@Override
public GuardedString convert(String source) {
    return new GuardedString(source.toCharArray());
}}

我在尝试运行应用程序时遇到的错误是:


应用程序无法启动


说明:

无法将“abc.guardedstring”下的属性绑定到 org.identityconnectors.common.security.GuardedString:

Property: abc.guardedstring
Value: Hello
Origin: class path resource [application-dev.properties] - 5:19
Reason: failed to convert java.lang.String to org.identityconnectors.common.security.GuardedString

操作:

更新应用程序的配置

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...