I have a Spring Boot Application, its file hierarchy:
src/
└── main/
└── java/
| ├── com.example/
| | ├── config/
| | | └──R2DBCConfiguration.java
| | ├── dao/
| | | └── UnitR2DBCRepository.java
| | └── R2DBCApplication.java
| └──resources/
| └── application.yml
└── test
└── java/
├── com.example/
| └── dao/
| └── R2DBCTest.java
└──resources/
└── application.yml
R2DBCConfiguration.java
@Configuration
@AllArgsConstructor
public class R2DBCConfiguration {
@Bean
public ConnectionFactory connectionFactory() {
return new PostgresqlConnectionFactory(PostgresqlConnectionConfiguration.builder(). ... .build());
}
@Bean
public DatabaseClient databaseClient() {
return DatabaseClient.builder().connectionFactory(connectionFactory()).build();
}
}
Unit2RDBCRepository.java
@Repository
public interface UnitR2DBCRepository extends ReactiveCrudRepository<Unit, UUID> { }
R2DBCApplication.java
@SpringBootApplication
public class R2DBCApplication{
public static void main(String... args) {
SpringApplication.run(R2DBCApplication.class, args);
}
}
Test.java
@SpringBootTest
@ContextConfiguration(classes = R2DBCConfiguration.class)
public class R2DBCTest {
@Autowired
private DatabaseClient client;
@Autowired
private UnitR2DBCRepository unitR2DBCRepository;
@Test
public void test() {
...
}
}
When I run R2DBCTest, I get the error:
NoSuchBeanDefinitionException: No qualifying bean of type 'com.example.dao.UnitR2DBCRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
question from:
https://stackoverflow.com/questions/65916929/why-bean-is-not-found-in-spring-boot-test 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…