java处理数据库密码加密配置时如何解密使用

首先配置文件中

<!-- 加密时候使用 -->
    <bean id="propertyConfig" class="sunwin.yog.dao.DecodePropertyConfigurer">
        <property name="locations">
            <list>
                <value>classpath:config.properties</value>
            </list>
        </property>
    </bean>

实现自定义DecodePropertyConfigurer类

/**
 * 扩展 配置文件数据库用户名,密码解密
 */
public class DecodePropertyConfigurer extends PropertyPlaceholderConfigurer {
    private  Logger log = Logger.getLogger(DecodePropertyConfigurer.class);
    @Override
    protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props){
        try{

            String password = props.getProperty("jdbc.password");
            //解密jdbc.password属性值,并重新设置
            props.setProperty("jdbc.password", EncodeUtil.decode(password));
            super.processProperties(beanFactory, props);

        }catch (Exception e){
            log.error(e+"\nDecrypt Error");
            e.printStackTrace();
        }

    }
}
发布了31 篇原创文章 · 获赞 1 · 访问量 5684

猜你喜欢

转载自blog.csdn.net/wjs040/article/details/91878677