Spring属性文件加密

使用Spring时,一般使用
<context:property-placeholder />

指定数据配置文件,然后通过读取属性值配置数据源
  <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
    <property name="url" value="${url}" />
    <property name="username" value="${username}" />
    <property name="password" value="${password}" />
    <property name="maxActive" value="200" />
    <property name="initialSize" value="2" />
    <property name="minIdle" value="5" />
    <property name="maxIdle" value="20" />
    <property name="maxWait" value="60000" />
    <property name="defaultAutoCommit" value="true" />
  </bean>

如果要求对数据配置文件加密,可以自定义属性读取类进行加解密操作。
public class CustomerPorpertyPlaceholder extends PropertyResourceConfigurer
	implements BeanNameAware, BeanFactoryAware  {
    protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props)
			throws BeansException {
        //属性读取并加解密
    }
}

applicationContext.xml中配置:
  <bean id="propertyConfigurer" class="CustomerPorpertyPlaceholder">
    <property name="locations">
     <list>
      <value>配置文件路径</value>
     </list>
    </property>
  </bean>

你可能感兴趣的:(java,spring,xml)