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

MrHanhan發表於2020-05-18

<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” 表示佔位符應首先針對系統屬性進行解析,然後針對任何本地屬性進行解析;

預設的是第一個:

相關文章