spring+mybatis集成過程中,報錯信息如下:
[ERROR] 2020-02-09 create connection SQLException, url: jdbc:mysql://127.0.0.1:3306/ems, errorCode 1045, state 28000
原因:spring默認會優先加載使用系統環境變量,此時,username實際上指的是當前計算機的用戶名。而不是取值配置文件中定義的username。
兩種解決方式:
(1)將datasource中的${username}換成了${name}就可以了,
(3)設置本地配置覆蓋系統配置
<context:property-placeholder local-override="true" location="classpath:conn.properties"></context:property-placeholder>
(2)使用標簽:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" p:localOverride="true">
<property name="locations" value="classpath:conn.properties"></property>
</bean>
