Spring属性加载 - 动态解密加密属性

时间:2013-12-17 08:24:54

标签: java spring encryption properties

我正在使用spring-PropertySourcesPlaceholderConfigurer公开的最新属性加载机制,并尝试动态解密加密属性。 PropertyPlaceholderConfigurer我可以覆盖resolvePlaceholder,并为其添加解密机制。

但是,我无法弄清楚如何在PropertySourcesPlaceholderConfigurer中做到这一点。尝试覆盖processProperties,并传入我的自定义ConfigurablePropertyResolver [使用getProperty Overriden],但这不起作用。

MutablePropertySources propertySources = new MutablePropertySources();

try {
    propertySources.addFirst(getExtendPortsProperties());
    propertySources.addFirst(new ResourcePropertySource("classpath:/X.properties"));
    propertySources.addFirst(new ResourcePropertySource("classpath:/Y.properties"));
} catch (IOException e) {
    throw new RuntimeException("failed to read property source", e);
}

这是我阅读属性的方式。然后,

PropertySourcesPlaceholderConfigurer result = new PropertySourcesPlaceholderConfigurer();
result.setPropertySources(firePropertiesSources);

这就是我设置属性的方式。

现在,这些道具中的一个属性是加密的,我需要指示Spring在用实际值替换占位符之前解密它。[我需要指定我的自定义实现]

1 个答案:

答案 0 :(得分:0)

而不是制作自己的,你看过jasypt吗?它具有您需要的确切功能。看看http://www.jasypt.org/spring31.html

相关问题