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。 
于是按照第一种写法又测试了一下,发现找到了。 

但是寻找的路径依旧: 


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值