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

    xiaoxiao2021-03-25  61

    **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。 于是按照第一种写法又测试了一下,发现找到了。 但是寻找的路径依旧: ps: 如果还没有解决,请检查你的数据库配置文件里面是不是多了空格,这也可能导致问题发生。

    转载请注明原文地址: https://ju.6miu.com/read-33019.html

    最新回复(0)