春季数据R2DBC:连接到mySQL的问题 - 找不到存储库bean
我正在尝试使用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.
application.yaml: 尝试定义spring.r2dbc.pool.enabled:false and 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);
}
}
任何帮助都将不胜感激。
I am trying to integrate MySql to spring boot application using r2dbc driver. While doing so encountering issue wherein the repository bean is not getting created. I saw similar questions but the approaches mentioned in those didn't help.
Error message below:
***************************
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.
application.yaml:
Tried to define spring.r2dbc.pool.enabled: false and spring.r2dbc.pool.enabled:. But both of this didn't help
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 dependencies
<!-- 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
@Repository
public interface StudentRepository extends ReactiveCrudRepository<Student, UUID> {
}
Student entity
@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;
}
Main class
I used @EnableR2dbcRepositories as well below but it didn't help much and getting same issue
@SpringBootApplication
public class StudentserviceApplication {
public static void main(String[] args) {
SpringApplication.run(StudentserviceApplication.class, args);
}
}
Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您的
StudentRepository
接口中,扩展r2dbcrepository
而不是eactivevecrudrepository
。我最近遇到了同样的问题,并解决了问题。
In your
StudentRepository
interface, extendR2dbcRepository
instead ofReactiveCrudRepository
.I recently had the same issue and that fixed it.
您在学生pojo中使用
uuid
作为ID,但是在存储库定义中,您使用long
。将其更改为uuid
如下You are using
UUID
as id in the Student POJO, but in repository definition you useLong
. Change it toUUID
as follows