单元测试报错
我在jdbc:properties中的
username = root
但是在调用之后单元测试
Access denied for user 'zqq'@'localhost' (using password: YES)
也就是说我登录用户名变成了我电脑的用户名zqq而不是root
所以我想知道${username}调用为啥会变?
我在jdbc:properties中的
username = root
但是在调用之后单元测试
Access denied for user 'zqq'@'localhost' (using password: YES)
也就是说我登录用户名变成了我电脑的用户名zqq而不是root
所以我想知道${username}调用为啥会变?
2016-05-09
原因:
context:property-placeholder 中属性system-properties-mode
Controls how to resolve placeholders against system properties. As of Spring 3.1, this attribute
value defaults to "ENVIRONMENT"
解决办法:
1、改用以下配置:
<bean id= "propertyConfigurer"
class= "org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" >
<property name= "locations">
<list>
<value> classpath:jdbc.properties</value >
</list>
</property>
</bean>
2、properties文件中的key不要与系统配置重名,比如 jdbcusername=root
3、将context:property-placeholder 中属性system-properties-mode 默认值配置成:NEVER
举报