您的位置:首页 > 其它

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

2017-03-12 11:52 671 查看
**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。

于是按照第一种写法又测试了一下,发现找到了。

但是寻找的路径依旧:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐