我正在使用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在用实际值替换占位符之前解密它。[我需要指定我的自定义实现]