问题描述
自从我用Jasypt的EncryptablePropertyPlaceholderConfigurer替换了Spring的PropertySourcesPlaceholderConfigurer之后,我一直无法读取通过@Value注释传递给应用程序的VM参数(例如:-Dtestvar = testVal)。 app.properties文件中的属性正在按预期方式读取和/或解密。但是VM参数只是不可读。应该使用通过VM参数传递的值覆盖app.properties上的属性。
配置曾经是什么(当读取VM参数并按预期工作时):
@Bean
public static PropertySourcesPlaceholderConfigurer myConfig() {
return new PropertySourcesPlaceholderConfigurer();
}
我当前的Jasypt EncryptablePropertyPlaceholderConfigurer配置看起来像这样,它替换了上面的内容:
@Bean
public static PooledPBEStringEncryptor configuEncryptor() {
PooledPBEStringEncryptor configuEncryptor = new PooledPBEStringEncryptor();
configuEncryptor.setConfig(environmentvariableConfig());
return configuEncryptor;
}
@Bean
public static EnvironmentStringPBEConfig environmentvariableConfig() {
final EnvironmentStringPBEConfig config = new EnvironmentStringPBEConfig();
config.setAlgorithm(ALGORITHM);
config.setPassword(PASSWORD);
return config;
}
@Bean
public static EncryptablePropertyPlaceholderConfigurer propertyPlaceholderConfigurer() {
EncryptablePropertyPlaceholderConfigurer propertyPlaceholderConfigurer = new EncryptablePropertyPlaceholderConfigurer(configuEncryptor());
propertyPlaceholderConfigurer.setLocations(
new ClassPathResource("app.properties")
);
propertyPlaceholderConfigurer.setIgnoreResourceNotFound(true);
propertyPlaceholderConfigurer.setIgnoreUnresolvablePlaceholders(true);
return propertyPlaceholderConfigurer;
}
使用Spring的PropertySourcesPlaceholderConfigurer时,读取外部传递的VM参数(覆盖app.properties中的props)没有问题。在实现Jasypt的EncryptablePropertyPlaceholderConfigurer之后,这已成为一个问题。有人能解决这个问题吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)