r2dbc的repository注入失败

简介: r2dbc的repository注入失败

怀疑与信仰,两者都是必需的。怀疑能把昨天的信仰摧毁,替明日的信仰开路。——罗曼·罗兰

今天springboot3使用r2dbc踩坑

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.ruben.repository.UserRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@jakarta.annotation.Resource(shareable=true, lookup="", name="", description="", authenticationType=CONTAINER, type=java.lang.Object.class, mappedName="")}

依赖大概是:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-r2dbc</artifactId>
    <version>3.0.2</version>
</dependency>
<dependency>
    <groupId>io.asyncer</groupId>
    <artifactId>r2dbc-mysql</artifactId>
    <version>1.0.3</version>
</dependency>

使用时:

import org.springframework.data.repository.reactive.ReactiveCrudRepository;
import org.springframework.stereotype.Repository;
import reactor.core.publisher.Flux;
@Repository
public interface UserRepository extends ReactiveCrudRepository<User, Long>{
}

乍一看没啥问题,但就是报错,最后发现控制台打印了一句INFO等级的日志:

2023-10-28T08:32:14.926+08:00  INFO [im-logic-service,,,] 50350 --- [           main] .RepositoryConfigurationExtensionSupport : Spring Data R2DBC - Could not safely identify store assignment for repository candidate interface com.ruben.repository.RoomRepository; If you want this repository to be a R2DBC repository, consider annotating your entities with one of these annotations: org.springframework.data.relational.core.mapping.Table (preferred), or consider extending one of the following types with your repository: org.springframework.data.r2dbc.repository.R2dbcRepository

原来是需要在实体类上加@Table注解或者接口继承R2dbcRepository。。。

目录
打赏
0
0
0
0
29
分享
相关文章
Spring中refresh分析之prepareBeanFactory方法详解
Spring中refresh分析之prepareBeanFactory方法详解
86 0
SpringBoot整合es7.x启动报错:Rejecting mapping update to [AAA] as the final mapping would have more than 1
SpringBoot整合es7.x启动报错:Rejecting mapping update to [AAA] as the final mapping would have more than 1
203 1
【问题记录(已解决)】springboot整合ssm报错‘url‘ attribute is not specified and no embedded datasource
【问题记录(已解决)】springboot整合ssm报错‘url‘ attribute is not specified and no embedded datasource
112 0
|
10月前
r2dbc的repository注入失败
r2dbc的repository注入失败
93 0
Spring中refresh分析之prepareRefresh方法详解
Spring中refresh分析之prepareRefresh方法详解
156 0
解决requried a bean of type xxx的问题(可能原因之一)
解决requried a bean of type xxx的问题(可能原因之一)
487 0
SpringBoot整合Druid报错记录:Failed to configure a DataSource: ‘url‘ attribute is not specified and no embe
SpringBoot整合Druid报错记录:Failed to configure a DataSource: ‘url‘ attribute is not specified and no embe
Mybatis提示Tag name expected的问题
Mybatis提示Tag name expected的问题
478 0
【异常】Mybatis中,SpringMVC中,SpringBoot项目中,出现There is no getter for property named 'xxxxxx'报错的解决方法
Mybatis中,SpringMVC中,SpringBoot项目中,出现There is no getter for property named 'xxxxxx'报错的解决方法
525 0