0

I have created a maven module for implementing spring batch in our project. My aim is to export data from database table to CSV file (basing on a repository implemented in another maven module).

In my Spring boot main class I have the following:

@SpringBootApplication(scanBasePackages = {"com.test"})
@ComponentScan({"com.test"})
public class MainBatchApplication {
    public static void main(String args []){
        SpringApplication.run(MainBatchApplication.class,args);
    }
}

The package com.test is the path of our implemented UserRepository I want to use to get all users from database.

Once I inject the UserRepository in my Spring Batch created maven module and once I run the spring boot app. I got the following error:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'batchConfiguration': Unsatisfied dependency expressed through field 'userRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List com.test.repositories.UserRepository.getFilteredByMonth(java.lang.String,java.util.Date,java.util.Date)!

The module where com.test if included in my batch maven module as dependency (pom.xml)

sk555
  • 828
  • 2
  • 8
  • 23
  • 1
    Share your Repository class also – Nicholas K Aug 15 '18 at 14:19
  • @NicholasK Thanks for answering, Repository class is good i see as I used it in my service – sk555 Aug 15 '18 at 14:20
  • You need to post your repository and especially your getFilteredByMonth method. But likely your query is not legit JQL, as in here: https://stackoverflow.com/questions/44647630/validation-failed-for-query-for-method-jpql, You probably need to mark your query as a native one. – Robert Moskal Aug 15 '18 at 14:34
  • @RobertMoskal i tried to comment the method getFiltredByMonth and i got another error with another repository that i din't used but in the same package where my used repository is. isn't womethong with the configuration ? is my componentScan annotation correct ? – sk555 Aug 15 '18 at 15:59
  • You'll have to post the repository code. – Robert Moskal Aug 15 '18 at 16:44

1 Answers1

0

You need to define configuration somewhere in your project with:

@Configuration
@EnableBatchProcessing
public class BatchConfiguration {
 ....
}

Then you would be able to inject your Repository here for writers.

It would need some more bean definition. See: https://spring.io/guides/gs/batch-processing/ for examples

AlexGera
  • 756
  • 9
  • 19