栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在Springboot中创建自定义Jasypt PropertySource

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在Springboot中创建自定义Jasypt PropertySource

这里有两个问题。

1)EncryptedPropertySourceLoader的加载需要高于标准PropertiesPropertySourceLoader的加载。这可以通过实现PriorityOrder接口来实现,如下所示:

public class EncryptedPropertySourceLoader implements PropertySourceLoader, PriorityOrdered{    private final StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();    public EncryptedPropertySourceLoader()    {        this.encryptor.setPassword("password"); //TODO: this could be taken from an environment variable    }    @Override    public String[] getFileExtensions()    {        return new String[]{"properties"};    }    @Override    public PropertySource<?> load(final String name, final Resource resource, final String profile) throws IOException    {        if (profile == null)        { //load the properties final Properties props = PropertiesLoaderUtils.loadProperties(resource); if (!props.isEmpty()) {     //create the encryptable properties property source     return new EncryptablePropertiesPropertySource(name, props, this.encryptor); }        }        return null;    }    @Override    public int getOrder()    {        return HIGHEST_PRECEDENCE;    }}

使用将从订单中

org.springframework.core.io.support.SpringFactoriesLoader
加载结果的类。意味着应首先返回此类,并将负责为*
.proerpties文件提供PropertySourceLoader实现。
org.springframework.boot.env.PropertySourceLoader``meta-INF/spring.factories``org.springframework.core.OrderComparator

2)第二个问题是可执行JAR / WAR的类加载问题,这似乎是由Windows上的Spring
Boot版本1.1.2.RELEASE中的错误引起的。降至版本1.1.1.RELEASE或版本1.1.3RELEASE解决了在maven外部运行时类和属性文件未加载的各种问题。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/383253.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号