idea開發springboot 的mysql資料庫連線問題
阿新 • • 發佈:2019-01-31
今天在家用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 2018There 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資料來源的屬性欄位,所以不識別,當改為如下設定,資料庫就連線上了。