spring 環境下怎麼對c3p0連接池用戶名和密碼加密

重寫spring中的PropertyPlaceholderConfigurer類

import java.util.Properties;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

public class DecryptPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer{

    @Override
    protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess,Properties props) throws BeansException {
        try {
            String encryptedUser = props.getProperty("c3p0.username");
            String encryptedPassword= props.getProperty("c3p0.password");
            String user = "";//這裏做用戶名解密
            String password = "";//這裏要對密碼做解密
            props.setProperty("c3p0.username", user);
            props.setProperty("c3p0.password", password);
        } catch (Exception e) {
            e.printStackTrace();
        }
        super.processProperties(beanFactoryToProcess, props);
    }
}

spring配置文件中使用重寫的類

 

<bean class="yourpackage.DecryptPropertyPlaceholderConfigurer">
          <property name="locations">
              <list>
                <value>classpath:app.properties</value>
            </list>
          </property>
</bean>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章