Spring使用Properties配置进行加密

来源:互联网 发布:运维和java哪个好 编辑:程序博客网 时间:2024/05/07 21:35

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);      }  } 





0 0
原创粉丝点击