spring中<context:property-placeholder/>一个坑

<context:property-placeholder location="classpath:db.properties" ></context:property-placeholder>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="${driver}"/>
        <property name="jdbcUrl" value="${url}"/>
        <property name="user" value="${username}"/>
        <property name="password" value="${password}"/>

运行结果:

检查了数据库配置文件OK,并且ctl能够跳转路径也没问题。

原来 Access denied for user 'M.han'@'localhost' (using password: YES),将系统本地的user去做了连接!

system-properties-mode="FALLBACK"

加上这个配置就行了。

看看他的描述:

"ENVIRONMENT" indicates placeholders should be resolved against the current Environment and against any local properties;
"NEVER" indicates placeholders should be resolved only against local properties and never against system properties;
"FALLBACK" indicates placeholders should be resolved against any local properties and then against system properties;
"OVERRIDE" indicates placeholders should be resolved first against system properties and then against any local properties;

“ENVIRONMENT” 表示占位符应根据当前环境和任何本地属性进行解析;

“NEVER” 表示占位符只应针对本地属性进行解析,而不应针对系统属性进行解析;

“FALLBACK” 表示占位符应根据任何本地属性进行解析,然后根据系统属性进行解析;

“OVERRIDE” 表示占位符应首先针对系统属性进行解析,然后针对任何本地属性进行解析;

默认的是第一个:

猜你喜欢

转载自www.cnblogs.com/Mr-hanexp/p/12910556.html