Reputation: 150
when i want to use @springBatchTest annotation without having a datasource in the project i get this error :
Error creating bean with name 'jobRepositoryTestUtils': Unsatisfied dependency expressed through method 'setDatasource'
Is there a way to tell @SpringBatchTest Annotation to only create JobLauncherTestUtils and not the JobRepositoryTestUtils or another solution to this problem. Thanks in advance.
Upvotes: 2
Views: 1541
Reputation: 31590
When using @SpringBatchTest
, it is expected that the test context contains a bean of type DataSource
. This is mentioned in the Javadoc of the annotation, here is an excerpt:
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
If all you need is a JobLauncherTestUtils
but not other test utilities, you can define a JobLauncherTestUtils
bean manually in your test class, something like:
@Bean
public JobLauncherTestUtils testUtils() {
JobLauncherTestUtils jobLauncherTestUtils = new JobLauncherTestUtils();
jobLauncherTestUtils.setJob(jobUnderTest);
return jobLauncherTestUtils;
}
Upvotes: 2