1. 程式人生 > >SSM整合問題:Cannot create PoolableConnectionFactory (Access denied for user 'Administrator'@'localhost'

SSM整合問題:Cannot create PoolableConnectionFactory (Access denied for user 'Administrator'@'localhost'

**org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Access denied for user 'Administrator'@'localhost' (using password: YES))**


檢視報錯原因可以知道是因為mysql資料庫連線的問題,連線不上,那問題出在那裡呢?

看日誌資訊:發現如下一段:

394 [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - Searching for key ‘username’ in [environmentProperties]
394 [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - Searching for key ‘username’ in [systemProperties]
395 [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - Searching for key ‘username’ in [systemEnvironment]
395 [main] DEBUG org.springframework.core.env.SystemEnvironmentPropertySource - PropertySource [systemEnvironment] does not contain ‘username’, but found equivalent ‘USERNAME’
395 [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - Found key ‘username’ in [systemEnvironment] with type [String] and value ‘Administrator’
395 [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - Found key ‘username’ in [environmentProperties] with type [String] and value ‘Administrator’

根據資料庫配置檔案尋找 username,我這裡的username是root,但是最後卻找到了Administrator. 問題就處在這裡了。
原來他找了一遍沒有找到,在systemEnvironment裡面去找了,看了是我的配置路徑有問題,讓他找不到:
<context:property-placeholder location="classpath:db.properties"/>

但是這個問題昨天卻沒有發生,於是我改一下寫法:

<bean id="propertyConfigurer"
          class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
> <property name="location" value="classpath:db.properties" /> </bean>

這回沒有報錯了。應該是解析出了問題。
我再把username改成 name試一下,因為系統裡面很可能有別的地方用的是username。
於是按照第一種寫法又測試了一下,發現找到了。
但是尋找的路徑依舊:
這裡寫圖片描述