如何解决HikariPoolInitializationException:无法初始化池:用户'root'@'localhost'的访问被拒绝使用密码:是
当我尝试从Spring Boot应用程序访问本地MySQL数据库时,出现上述错误。
配置和属性文件如下。
application.properties
```spring.datasource.url=jdbc:mysql://localhost:3306/sample_db
spring.datasource.username=root
spring.datasource.password=Password123
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.database-platform = org.hibernate.dialect.MySQL5Dialect
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto = update```
如果我使用,这可以正常工作
```spring.datasource.url=jdbc:mysql://localhost:3306/sample_db?user=root&password=Password123```
DatabaseRepositoryConfig.java
@Configuration
@EnableTransactionManagement
public class DatabaseRepositoryConfig {
@Value("${spring.datasource.driver-class-name}")
private String driverClass;
@Value("${spring.datasource.url}")
private String jdbcUrl;
@Value("${spring.datasource.username}")
private String jdbcUserName;
@Value("${spring.datasource.password}")
private String jdbcPassword;
@Bean
public DataSource dataSource() {
LOG.info("Repository Config ");
HikariConfig dataSourceConfig = new HikariConfig();
dataSourceConfig.setDriverClassName(driverClass);
dataSourceConfig.setJdbcUrl(jdbcUrl);
dataSourceConfig.setUsername(jdbcUserName);
dataSourceConfig.setPassword(jdbcPassword);
return new HikariDataSource(dataSourceConfig);
}
@Bean
public EntityManagerFactory entityManagerFactory() {
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
vendorAdapter.setGenerateDdl(true);
LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
factory.setJpaVendorAdapter(vendorAdapter);
factory.setPackagesToScan("com.project.db.entities");
factory.setDataSource(dataSource());
factory.afterPropertiesSet();
return factory.getObject();
}
@Bean
public PlatformTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) {
return new JpaTransactionManager(entityManagerFactory);
} ```
**Error:**
Caused by: com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: Access denied for user 'root'@'localhost' (using password: YES)
I tried accessing mySQL from command line and I am able to login as root with the same password. Please let me know what properties are causing this issue?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。