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.
You are using
UUID
as id in the Student POJO, but in repository definition you useLong
. Change it toUUID
as follows