1

this is my first post on this forum so please go easy on me if a made mistake or else. I'm using spring-boot batch with mongdb and everything works fine but I running in trouble when I have to test my batch. My Batchconfiguration is based on multiple jobs (4 jobs), so

  1. 1st trouble when I used JobLauncherTestUtils spring doesn't know which job to inject and I don't know how to specify that to test the jobs one by one.
  2. 2nd trouble when I separate my configuration to testing only one job, JobLauncherTestUtils couldn't been creating because it's need dataSource, as I used MongoDb with mongotemplate I don't use dataSource.

the stack error look like :

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jobRepositoryTestUtils': Unsatisfied dependency expressed through method 'setDataSource' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'javax.sql.DataSource' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}

Hope anybody will help me to find a solution. Thanks in advance.

0

1 Answer 1

1

1st trouble when i used JobLauncherTestUtils spring don't know wich job to inject and i don't know how to specify that to test the jobs one by one.

You can specify which job to launch using JobLauncherTestUtils#setJob. Please see JobLauncherTestUtils throws NoUniqueBeanDefinitionException while trying to test spring batch steps

2nd trouble when I separate my configuration to testing only one job, JobLauncherTestUtils couldn't been creating because it's need dataSource, as I used MongoDb with mongotemplate I don't use dataSource.

According to the error Error creating bean with name 'jobRepositoryTestUtils', it is not JobLauncherTestUtils that could not be created but jobRepositoryTestUtils. The repository test utils is a convenience class to create and remove job executions from a database (See its javadoc). So it requires a datasource. If you don't have a data source in your test context, you need to remove this bean declaration.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank for your reply, this link help me to solve my problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.