Spring对properties文件的安全项进行加密
最近在对公司的www官网项目进行安全整改,其中有一项就是对配置文件中的安全信息进行加密处理,不得明文展示,比如数据库的连接串,用户名,密码等。
Spring在对properties文件进行处理得时候有一个类叫做PropertyPlaceholderConfigurer
,这个类可以指定加载的properties文件。
比如加载一个jdbc.properties
jdbc.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8
jdbc.username=test
jdbc.password=test
然后在XML中做如下配置:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigure">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="ignoreResourceNotFound" value="true" />
<property name="locations">
<list>
<value>classpath:jdbc.properties</value>
</list>
</property>
</bean>