微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决从字符串转换为 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 举报,一经查实,本站将立刻删除。