【发布时间】:2022-02-02 12:11:28
【问题描述】:
完整的错误是
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
我在 application.yml 中设置了以下数据源
spring:
datasource:
reader:
username: admin
password: password
driver-class-name: com.mysql.cj.jdbc.Driver
jdbcUrl: jdbc:mysql://<aurora-mysql-reader-endpoint_instance>:3306/credentialdb
pattern: get*,find*
writer:
username: admin
password: password
driver-class-name: com.mysql.cj.jdbc.Driver
jdbcUrl: jdbc:mysql://<aurora-mysql-reader-endpoint_instance>/credentialdb
pattern: add*,update*
jpa:
hibernate:
ddl-auto: update
我做了谷歌,排名第一的评论是
@SpringBootApplication(exclude={DataSourceAutoConfiguration.class})
但是导致下面的代码崩溃
public interface CredentialRepository extends CrudRepository<CredentialEntity, Long> {
}
@Service
public class CredentialServicesImpl implements CredentialServices {
@Autowired
CredentialRepository credentialrepository;
例外
NoSuchBeanDefinitionException: No qualifying bean of type 'com.opsec.shared.harvesting.fetcher.credentialmanger.repository.CredentialRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
那么,我该如何绕过原始异常 配置数据源失败:未指定“url”属性
我认为这可能是一个依赖问题,我正在尝试连接到 AWS RDS aurora mysql,但我的依赖是
<!-- spring -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!-- SQL -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.15</version>
</dependency>
【问题讨论】:
-
您是否在 CredentialRepository 中添加了
@Repository注释 -
把jdbcUrl改成url
-
是的,我已经尝试使用@Repository 注释并将 jdbcUrl 更改为 url。我觉得它可能与 pom 相关,缺少依赖
标签: java mysql spring-boot amazon-aurora