我正在尝试在 micronaut 中编写集成测试。
我有一个控制器类:
@Controller("/hello")
public class HelloController {
@Inject
private HelloRepository helloRepository;
@Get("/")
public HttpResponse get() {
return HttpResponse.ok(helloRepository.findAll());
}
}
我正在尝试为它编写一个集成测试,例如:
@MicronautTest
public class HelloControllerSpec {
@Inject
EmbeddedServer embeddedServer;
@BeforeEach
void setUp() {
initMocks(this);
}
@Test
public void testIndex() throws Exception {
try(RxHttpClient client = embeddedServer.getApplicationContext().createBean(RxHttpClient.class, embeddedServer.getURL())) {
client.toBlocking().exchange("/hello").status();
}
}
}
但我不断收到错误:
No backing RepositoryOperations configured for repository. Check your configuration and try again
我放在“src/test/java/resources/”下的 application.yml 文件具有以下数据源实现:
datasources:
default:
url: jdbc:h2:mem:devDb
driverClassName: org.h2.Driver
username: sa
password: 'sa'
schema-generate: CREATE_DROP
dialect: H2
jpa:
default:
packages-to-scan:
- 'com.myproject.project'
properties:
hibernate:
hbm2ddl:
auto: update
show_sql: true
我也将它包含在我的 build.gradle 文件中
runtime 'com.h2database:h2'
有没有办法解决这个问题?
编辑:这是我的存储库类
@Repository
public interface HelloRepository extends CrudRepository<BufferConditionEntity, Long> {}