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 'root '@'localhost' (using password: YES))
### The error may exist in com/sample/mappers/EmployeeMapper.xml
### The error may involve com.sample.dao.EmployeeDao.listall
### The error occurred while executing a query
### 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 'root '@'localhost' (using password: YES))java
notice: the user is 'root ' not 'root'mysql
這個問題大體就是須要檢查你的數據源配置即Resource中的:url,username,passwordspring
url這個通常是"jdbc:mysql://localhost:3306/test",必定要注意3306,這個是你數據庫鏈接用的端口,能夠把它改爲別的,可是若是你用的tomcat容器,別把它寫成8080,這樣就會產生Cannot create PoolableConnectionFactory (Communications link failure問題,還有就是url=jdbc:mysql://localhost:3306/test中的localhost,也不是隨便配置的,要看你的數據庫中的from hostsql
我當時實在MySql Workbench5.2 CE中的 Users and Privileges中,有個Server Access Management數據庫
User From Host 你看From Host中有沒有localhost,若是有你就能寫成url=jdbc:mysql://localhost:3306/test,要是from host有127.0.0.1的話,也能夠寫成url=jdbc:mysql://127.0.0.1:3306/testapache
還有就是 username= 這個必定要寫正確,我當時寫的是name= ,結果mysql找不到username,而後他自動把username設爲"",以致於錯誤提示: java.sql.SQLException: Access denied for user ‘’ @'localhost' (using password: YES) 你看到@前面是兩個單引號了嗎,那就是我沒輸入username而致使默認的默認username,其實這個錯誤也能夠用設置權限改,可是那是mysql內容,就不說了。tomcat
總結起來就是:url端口要寫對,不能寫其餘程序被佔用的,127.0.01仍是localhost要看數據庫裏面有哪一個,還要就是把對的驅動放入項目中的WEB-INF/lib裏,這裏提一下不用再放到tomcat的lib中。mybatis