我遵循这链接来使用spring数据实现R2DBC。那个项目有巨大的POM,因为它也演示了其他特性。因此,我尝试只需要H2的spring和H2的依赖项。
我的目标是:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!--For testing-->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.199</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- junit 5 -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<!--For reactive-->
<dependency>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-h2</artifactId>
<version>0.8.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-r2dbc</artifactId>
<version>1.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
</dependency>
<!---->
<dependencies> 然后,我将存储库定义为:
public interface ReactiveFeatureRepository extends ReactiveCrudRepository<Feature, UUID> {
}Feature是实体类。
我在src/test/ application.properties中配置了application.properties:
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1
spring.datasource.username=sa
spring.datasource.password=sa在试验中:
@ExtendWith(SpringExtension.class)
@SpringBootTest
public class ReactiveFeatureRepositoryTest {
@Autowired
ReactiveFeatureRepository rfr;
@Autowired
DatabaseClient client;
@Autowired
H2ConnectionFactory factory;
...
...
}但是,当我尝试运行测试时,我会得到大量的日志,其中列出了“占位匹配”和“负面匹配”,最后是:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name
'x.y.z.ReactiveFeatureRepositoryTest': Unsatisfied dependency expressed
through field 'rfr'; nested exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type
'x.y.z.ReactiveFeatureRepository' available: expected at least 1 bean which
qualifies as autowire candidate. Dependency annotations:
{@org.springframework.beans.factory.annotation.Autowired(required=true)}
at 与样例项目相比,我遗漏了什么?
https://stackoverflow.com/questions/62273512
复制相似问题