我正在使用Spring Boot 1.2.3,我想了解是否可以在将属性值注入使用@ConfigurationProperties注释的bean之前对其进行解密.
假设我在application.properties文件中有以下内容:
appprops.encryptedProperty = ENC(ENCRYPTEDVALUE)
和这样的示例应用程序:
package aaa.bb.ccc.propertyresearch;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import javax.annotation.PostConstruct;
@SpringBootApplication
@EnableConfigurationProperties(PropertyResearchApplication.ApplicationProperties.class)
public class PropertyResearchApplication {
public static void main(String[] args) {
SpringApplication.run(PropertyResearchApplication.class,args);
}
@ConfigurationProperties("appprops")
public static class ApplicationProperties {
private String encryptedProperty;
@PostConstruct
public void postConstruct() throws Exception {
System.out.println("ApplicationProperties --> appprops.encryptedProperty = " + encryptedProperty);
}
public String getEncryptedProperty() {
return encryptedProperty;
}
public void setEncryptedProperty(String encryptedProperty) {
this.encryptedProperty = encryptedProperty;
}
}
}
在过去,我使用自定义的PropertySourcesPlaceholderConfigurer来实现此目的,但它需要设置如下结构:
@Component
public class ApplicationProperties {
@Value("${appprops.enrcyptedProperty}")
private String encryptedProperty;
@PostConstruct
public void postConstruct() throws Exception {
System.out.println("ApplicationProperties --> appprops.encryptedProperty = " + encryptedProperty);
}
public String getEncryptedProperty() {
return encryptedProperty;
}
}
虽然这本身并不坏,但我想看看我是否可以利用加密属性的@ConfigurationProperties的细节.
最佳答案