/** * @author xichao.dong * @email 406592176@qq.com * @date 2014-8-15 上午8:50:38 * @company (开发公司) 珠海市冰川软件有限公司 * @copyright (版权) 本文件归属珠海市冰川软件有限公司所有 * @version V1.0 * @modify (修改) : 2014-8-15 上午8:50:38 xichao.dong * @Review (审核人) :xichao.dong */ package com.glacier.basic.config; import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; import com.glacier.basic.util.DESUtils; /** * @ClassName: EncryptPropertyPlaceholderConfigurer * @Description: TODO(Bean启动读取资源文件解密配置类) * @author xichao.dong * @email 406592176@qq.com * @date 2014-8-15 上午8:50:38 */ public class EncryptPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer { // 要进行解密的属性请放在数组里 private String[] encryptPropNames = { "connection.username", "connection.password", "mail.password" }; @Override protected String convertProperty(String propertyName, String propertyValue) { if (isEncryptProp(propertyName)) { String decryptValue = DESUtils.getDecryptString(propertyValue); return decryptValue; } else { return propertyValue; } } /** * 判断是否是加密的属性 * @param propertyName * @return */ private boolean isEncryptProp(String propertyName) { for (String encryptPropName : encryptPropNames) { if (encryptPropName.equals(propertyName)) { return true; } } return false; } }