@springBatchTest 没有数据源错误
@springBatchTest with no datasource Error
当我想在项目中没有数据源的情况下使用@springBatchTest 注释时,出现此错误:
Error creating bean with name 'jobRepositoryTestUtils': Unsatisfied dependency expressed through method 'setDatasource'
有没有办法告诉@SpringBatchTest 注解只创建 JobLauncherTestUtils 而不是 JobRepositoryTestUtils 或此问题的其他解决方案。
提前致谢。
使用 @SpringBatchTest
时,测试上下文应包含 DataSource
类型的 bean。这个在注释的Javadoc中有提到,这里摘录:
It should be noted that JobLauncherTestUtils requires a Job bean
and that JobRepositoryTestUtils requires a DataSource bean. Since
this annotation registers a JobLauncherTestUtils and a JobRepositoryTestUtils
in the test context, it is expected that the test context contains
a single autowire candidate for a Job and a DataSource
如果您只需要一个 JobLauncherTestUtils
而不是其他测试实用程序,您可以在测试 class 中手动定义一个 JobLauncherTestUtils
bean,例如:
@Bean
public JobLauncherTestUtils testUtils() {
JobLauncherTestUtils jobLauncherTestUtils = new JobLauncherTestUtils();
jobLauncherTestUtils.setJob(jobUnderTest);
return jobLauncherTestUtils;
}
当我想在项目中没有数据源的情况下使用@springBatchTest 注释时,出现此错误:
Error creating bean with name 'jobRepositoryTestUtils': Unsatisfied dependency expressed through method 'setDatasource'
有没有办法告诉@SpringBatchTest 注解只创建 JobLauncherTestUtils 而不是 JobRepositoryTestUtils 或此问题的其他解决方案。 提前致谢。
使用 @SpringBatchTest
时,测试上下文应包含 DataSource
类型的 bean。这个在注释的Javadoc中有提到,这里摘录:
It should be noted that JobLauncherTestUtils requires a Job bean
and that JobRepositoryTestUtils requires a DataSource bean. Since
this annotation registers a JobLauncherTestUtils and a JobRepositoryTestUtils
in the test context, it is expected that the test context contains
a single autowire candidate for a Job and a DataSource
如果您只需要一个 JobLauncherTestUtils
而不是其他测试实用程序,您可以在测试 class 中手动定义一个 JobLauncherTestUtils
bean,例如:
@Bean
public JobLauncherTestUtils testUtils() {
JobLauncherTestUtils jobLauncherTestUtils = new JobLauncherTestUtils();
jobLauncherTestUtils.setJob(jobUnderTest);
return jobLauncherTestUtils;
}