我有一个spring启动应用程序,它的文件层次结构:
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> { }
r2dbcaplication.java文件
@SpringBootApplication
public class R2DBCApplication{
public static void main(String... args) {
SpringApplication.run(R2DBCApplication.class, args);
}
}
测试.java
@SpringBootTest
@ContextConfiguration(classes = R2DBCConfiguration.class)
public class R2DBCTest {
@Autowired
private DatabaseClient client;
@Autowired
private UnitR2DBCRepository unitR2DBCRepository;
@Test
public void test() {
...
}
}
运行r2dbctest时,出现错误:
nosuchbeandefinitionexception:没有类型为“com.example.dao.unitr2dbcRecepository”的限定bean可用:至少需要1个符合autowire候选的bean。依赖项注解:{@org.springframework.beans.factory.annotation.autowired(required=true)}
暂无答案!
目前还没有任何答案,快来回答吧!