【发布时间】:2022-10-18 16:52:53
【问题描述】:
我正在尝试使用 r2dbc 驱动程序将 MySql 集成到 Spring Boot 应用程序。这样做时会遇到未创建存储库 bean 的问题。我看到了类似的问题,但其中提到的方法没有帮助。
下面的错误信息:
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 4 of constructor in com.abc.studentservice.utils.impl.HostelImpl required a bean of type 'com.abc.studentservice.repository.StudentRepository' that could not be found.
Action:
Consider defining a bean of type 'com.abc.studentservice.repository.StudentRepository' in your configuration.
应用程序.yaml:试图定义 spring.r2dbc.pool.enabled: false 和 spring.r2dbc.pool.enabled:。但这两者都没有帮助
spring:
profiles:
active: devo
r2dbc:
url: r2dbc:pool:mysql://localhost/student
username: mysql
password: mysql
pool:
initial-size: 10
max-size: 50
max-idle-time: 30m
validation-query: SELECT 1
data:
r2dbc:
repositories:
enabled: true
Maven 依赖项
<!-- Springboot data -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-r2dbc</artifactId>
<version>2.4.5</version>
</dependency>
<!-- Enable connection pooling -->
<dependency>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-pool</artifactId>
<version>0.8.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.3.6</version>
</dependency>
<!-- Reactive Mysql -->
<dependency>
<groupId>dev.miku</groupId>
<artifactId>r2dbc-mysql</artifactId>
<version>0.8.2.RELEASE</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.23</version>
</dependency>
存储库
@Repository
public interface StudentRepository extends ReactiveCrudRepository<Student, UUID> {
}
学生实体
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table("student")
public class Student {
@Id
@Column("id")
private UUID id;
@Column("first_name")
private String firstName;
@Column("last_name")
private String lastName;
}
主班我在下面也使用了@EnableR2dbcRepositories,但它并没有太大帮助并且遇到了同样的问题
@SpringBootApplication
public class StudentserviceApplication {
public static void main(String[] args) {
SpringApplication.run(StudentserviceApplication.class, args);
}
}
任何帮助,将不胜感激。
【问题讨论】:
标签: spring-boot spring-data spring-data-r2dbc r2dbc-mysql