Spring 中的.properties 属性(jdbc.password)加密

编程入门 行业动态 更新时间:2024-10-19 07:25:59

Spring 中的.properties <a href=https://www.elefans.com/category/jswz/34/1771415.html style=属性(jdbc.password)加密"/>

Spring 中的.properties 属性(jdbc.password)加密

 

 

1、复写processProperties方法实现 

 

package com.*.*;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 PropertyPlaceholderConfigurerTest extends PropertyPlaceholderConfigurer {protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props) throws BeansException { String password = props.getProperty("jdbc.password"); String username = props.getProperty("jdbc.username"); try {if (password != null) { //解密jdbc.password属性值,并重新设置 //Crypt.decrypt:自己编写的对应的解密方法(本文采用aes算法,aes网上有很多就不写出来了)props.setProperty("jdbc.password", Crypt.decrypt(password));} if (username != null) { props.setProperty("jdbc.username", Crypt.decrypt(username));} super.processProperties(beanFactory, props);} catch (Exception e) {e.printStackTrace();} }
}

  

<!-- 不加密时候使用使用spring自带的 -->


2、xml配置

<!-- 不加密时候使用使用spring自带的 -->

<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"><property name="locations"><list><value>classpath:jdbc.properties</value>   <value>classpath:roles.properties</value></list></property>
</bean>

 

<!-- 加密时候使用自己复写过的 -->

<bean id="propertyConfigurer"
class="com.*.*.PropertyPlaceholderConfigurerTest"><property name="locations"><list><value>classpath:jdbc.properties</value><value>classpath:roles.properties</value></list></property>
</bean>

 

3、原文

jdbc.username=F4B2DEB6F8FA201C5783A959CE1C3180
jdbc.password=F4B2DEB6F8FA201C5783A959CE1C3180

 

更多推荐

Spring 中的.properties 属性(jdbc.password)加密

本文发布于:2024-03-07 10:00:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1717518.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性   properties   Spring   jdbc   password

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!