Spring使用Properties配置進行加密

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





發佈了35 篇原創文章 · 獲贊 9 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章