spring配置使用Properties時,字段要求加密。不多說,直接上代碼。
使用自定義的propertyConfigurerl類。
<bean id="propertyConfigurer" class="com.cneport.cusoa.config.MyConfigurer">
<property name="locations">
<list>
<value>/WEB-INF/deploy.properties</value>
</list>
</property>
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
destroy-method="close">
<property name="driverClassName" value="${jdbc.driver}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
解密類propertyConfigurerl:public class MyConfigurer extends PropertyPlaceholderConfigurer {
@Override
protected void processProperties(
ConfigurableListableBeanFactory beanFactory, Properties props)
throws BeansException {
String password = props.getProperty("jdbc.password");
if (password != null ) {
props.setProperty("jdbc.password", IDEAEncrytion.getDesString(password));
(解密方法)
}
super.processProperties(beanFactory, props);
}
}