jdbc.properties内容进行保护

实现思路,在获得mybatis.properties的值时,改变键值的值,从而保护mybatis.properties中储存的数据
在applicatcontext.xml引入实体两个实体Bean和El表达式

id="ConvertPwdPropertyConfigurer" 
        class="cn.bdqn.com.cardDemo.commonUtil.ConvertPwdPropertyConfigurer"
       p:location="classpath:mybatis.properties"/>
    id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
     <property name="username" value="${username}">property>
     <property name="password" value="${password}">property>
     <property name="driverClassName" value="${driver}">property>
     <property name="url" value="${url}">property>
     

重写PropertyPlaceholderConfigurer的方法 ,可以从java代码中寻找mybatis.properties中相同属性名,不同值,代替
mybatis.properties中值

public class ConvertPwdPropertyConfigurer extends PropertyPlaceholderConfigurer{
    @Override
    protected String convertProperty(String propertyName, String propertyValue) {
        System.out.println("=================="+propertyName+":"+propertyValue);
        if("username".equals(propertyName)){
            return "root";
        }
        if("password".equals(propertyName)){
            return "ok";
        }
        return propertyValue;
    }
}

你可能感兴趣的:(jdbc.properties内容进行保护)