我在数据库中有一个加密的密码,在application.properties中有一个占位符 数据库
KPW=ENC(somebigencryptedpwd=)
application.properties
KPW=${KPW}
豆类: @Bean
public static PlaceholderManager getPropertyConfigurer() throws IOException{
PlaceholderManager propUtils = new PlaceholderManager(); //this class extends PropertyPlaceholderConfigurer and override postProcessBeanFactory
propUtils.setDataSourceName("DSXA");
propUtils.setLocalOverride(true);
return propUtils;
}
@Bean
public static EnvironmentStringPBEConfig environmentVariablesConfiguration() {
EnvironmentStringPBEConfig environmentVariablesConfiguration = new EnvironmentStringPBEConfig();
environmentVariablesConfiguration.setAlgorithm("PBEWithMD5AndDES");
environmentVariablesConfiguration.setPasswordEnvName("APP_ENCRYPTION_PASSWORD");
return environmentVariablesConfiguration;
}
@Bean
public static PBEStringEncryptor configurationEncryptor() {
StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
encryptor.setConfig(environmentVariablesConfiguration());
return encryptor;
}
@Bean
public static PropertyPlaceholderConfigurer propertyConfigurer() {
EncryptablePropertyPlaceholderConfigurer propertyConfigurer = new EncryptablePropertyPlaceholderConfigurer(configurationEncryptor());
propertyConfigurer.setLocation(new ClassPathResource("application.properties"));
// propertyConfigurer.setLocation(resource);
return propertyConfigurer;
}
用法:
<bean id="keSender" class="org.springframework.ws.transport.http.HttpComponentsMessageSender">
<property name="credentials">
<bean class="org.apache.http.auth.UsernamePasswordCredentials">
<constructor-arg value="${KID}"/>
<constructor-arg value="${KPW}"/>
</bean>
</property>
</bean>
如果我使用@Value注入KPW并使用端点返回它,那么我将从DB获得值。但是我该如何在可加密的占位符之后打印密码,以查看它被解密并正确