Spring整合MyBatis:Cannot create PoolableConnectionFactory (Access denied for user 'root '@'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 'root  '@'localhost' (using password: YES))
### The error may exist in file [D:\eclipsefile\myssm\target\classes\test\mapping\UserMapper.xml]
### The error may involve test.Dao.IUserDao.selectByPrimaryKey
### 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))


原因:

1,在jdbc属性配置文件中
      url=jdbc:mysql://localhost:3306/test
      user=root ....等尾部有空格存在,导致异常

(我的配置文件尾部有空格存在,害得我在找了半天,TMD就是几个空格的问题)

2.当前连接数据库的用户权限问题。新建一个用户,并赋予相应的数据操作权限

3.好好检查对应的配置.......


  • 5
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
Spring Boot整合Mybatis-Plus多数据源时,出现“Access denied for user 'root'@'localhost' (using password: NO)”错误,可能是因为配置文件中的密码没有正确识别。可以尝试以下解决方法: 1.检查配置文件中的密码是否正确,特别是在使用yml文件时,需要注意缩进和格式是否正确。 2.在配置文件中明确指定使用的数据源,例如: ```java @Configuration @MapperScan(basePackages = "com.example.demo.mapper") public class DataSourceConfig { @Bean(name = "dataSource1") @ConfigurationProperties(prefix = "spring.datasource.ds1") public DataSource dataSource1() { return DataSourceBuilder.create().build(); } @Bean(name = "dataSource2") @ConfigurationProperties(prefix = "spring.datasource.ds2") public DataSource dataSource2() { return DataSourceBuilder.create().build(); } @Bean(name = "dynamicDataSource") public DynamicDataSource dynamicDataSource(@Qualifier("dataSource1") DataSource dataSource1, @Qualifier("dataSource2") DataSource dataSource2) { Map<Object, Object> targetDataSources = new HashMap<>(); targetDataSources.put(DataSourceEnum.DATA_SOURCE1.getValue(), dataSource1); targetDataSources.put(DataSourceEnum.DATA_SOURCE2.getValue(), dataSource2); return new DynamicDataSource(dataSource1, targetDataSources); } } ``` 3.检查数据库用户的权限是否正确,可以使用以下命令修改密码: ```sql USE mysql;#mysql配置库 ALTER USER root@localhost IDENTIFIED BY 'newpasswd3'; # 修改密码 ```

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值