PropertyPlaceholderConfigurer
을 확장하고 org.springframework.beans.factory.config.PropertyResourceConfigurer.convertPropertyValue(String)
메서드를 재정의하면 "{EAS}"
으로 시작하는 경우 암호를 해독 할 수 있습니다. 다음 클래스와 같은 뭔가 PropertyPlaceHolder
로 사용할 수 있습니다 :
package foo.bar;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
public class EncryptationAwarePropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer{
@Override
protected String convertPropertyValue(String originalValue) {
if (originalValue.startsWith("{AES}")) {
return decrypt(originalValue.substring(5));
}
return originalValue;
}
private String decrypt(String value) {
return value.toLowerCase(); // here your decryption logic
}
}
이
귀하의 문맥 PropertyPlaceholder
과 같이 선언 할 것이다 :
<bean class="foo.bar.EncryptationAwarePropertyPlaceholderConfigurer">
<property name="location">
<value>my.properties</value>
</property>
</bean>
당신은 같은 속성을 사용하는 것이 쉬운 같은 :
@Value("${encryptedMyProtectedValue}")
private String decryptedValue;
편집 : org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(ConfigurableListableBeanFactory)
기본적으로 속성을 로컬 Properties 개체에로드하고 변환하고 처리합니다. 처리는 org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties(ConfigurableListableBeanFactory, Properties)
을 호출하여 발생합니다. org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
을 사용하면 Properties
객체는 빈 처리 후 메모리에 보관되지 않습니다. 기본적으로 컨텍스트에서 콩의 속성을 설정하는 데만 사용되며 처리됩니다.
내가 이미 그 부분을 통해 얻은 것처럼 당신에게 +1을줍니다 :-). 내 질문을 편집 중입니다 –
마지막 편집 확인 :-) –