错误日志:
java.sql.SQLException: Access denied for user 'xxx'@'localhost' (using password: YES)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129) ~[mysql-connector-java-8.0.25.jar:8.0.25]
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) ~[mysql-connector-java-8.0.25.jar:8.0.25]
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:833) ~[mysql-connector-java-8.0.25.jar:8.0.25]
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:453) ~[mysql-connector-java-8.0.25.jar:8.0.25]
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246) ~[mysql-connector-java-8.0.25.jar:8.0.25]
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198) ~[mysql-connector-java-8.0.25.jar:8.0.25]
at com.mysql.cj.jdbc.MysqlDataSource.getConnection(MysqlDataSource.java:416) ~[mysql-connector-java-8.0.25.jar:8.0.25]
at com.mysql.cj.jdbc.MysqlDataSource.getConnection(MysqlDataSource.java:128) ~[mysql-connector-java-8.0.25.jar:8.0.25]
at com.mysql.cj.jdbc.MysqlDataSource.getConnection(MysqlDataSource.java:113) ~[mysql-connector-java-8.0.25.jar:8.0.25]
....
2022-07-10 11:46:33.555 INFO 23360 --- [ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL57Dialect
2022-07-10 11:46:33.967 WARN 23360 --- [ restartedMain] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 1045, SQLState: 28000
2022-07-10 11:46:33.967 ERROR 23360 --- [ restartedMain] o.h.engine.jdbc.spi.SqlExceptionHelper : Access denied for user 'xxx'@'localhost' (using password: YES)
2022-07-10 11:46:33.972 ERROR 23360 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Failed to initialize JPA EntityManagerFactory: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution
2022-07-10 11:46:33.973 WARN 23360 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution
2022-07-10 11:46:33.975 INFO 23360 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2022-07-10 11:46:33.984 INFO 23360 --- [ restartedMain] ConditionEvaluationReportLoggingListener :
可能的问题
1. 配置了数据库连接池:
问题: 配置了数据库连接池:spriing.datasource.type: com.mysql.cj.jdbc.MysqlConnectionPoolDataSource
解决办法 改用阿里巴巴的连接池
1. pom文件添加依赖
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.2.6</version>
</dependency>
2. 修改 yml 文件
spriing.datasource.type: com.alibaba.druid.pool.DruidDataSource