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里面去找了,看了是我的配置路径有问题,让他找不到:

但是这个问题昨天却没有发生,于是我改一下写法:


        
    

这回没有报错了。应该是解析出了问题。
我再把username改成 name试一下,因为系统里面很可能有别的地方用的是username。
于是按照第一种写法又测试了一下,发现找到了。
但是寻找的路径依旧:
这里写图片描述
ps: 如果还没有解决,请检查你的数据库配置文件里面是不是多了空格,这也可能导致问题发生。

你可能感兴趣的:(Questions,&,Answers,Spring)