idea开发springboot 的mysql数据库连接问题

今天在家用idea进行springboot开发,前面一些坑相对避免了,但是到数据库这块总是连接不上,报错主要是:

Access denied for user 'root'@'localhost' (using password: NO)

网页上显示错误

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Sun May 06 15:18:14 CST 2018
There was an unexpected error (type=Internal Server Error, status=500).
nested exception is org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: NO) ### The error may exist in file [D:\test\target\classes\mapper\User.xml] ### The error may involve com.example.mapper.UserMapper.getUserById ### The error occurred while executing a query ### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: NO)

我检查我的密码等都是正确的,网上各种查,最后,原来是被idea坑了,

根据idea的提示写出来的数据源信息是:

 
 
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/test
spring.datasource.data-username=root
spring.datasource.data-password=123456
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

这个data-username,data-password,driver-class-name不是jdbc数据源的属性字段,所以不识别,当改为如下设置,数据库就连接上了。


猜你喜欢

转载自blog.csdn.net/zuixiaoyao_001/article/details/80215008