I am working on spring batch with spring boot 2.X application, actually its existing code i am checked out from git. While running the application it fails due to below error on
I was also having the same problem, for me following solution worked perfectly fine:
I had annotated my class as @AllArgsConstructor
by importing import lombok.AllArgsConstructor
I had just removed this annotation and the code starts working.
Hope this may help someone.
Add a public default constructor in your class. For example.
public User() {
}
Make sure you are using spring-boot-starter-data-jpa
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
You defined something like this:
@Component
public class InputItemReader{
public InputItemReader(String input){
...
}
}
The name of your class suggest that your object is not a bean, just a simple object. You should try to use it in classic way:
new InputItemReader(myString);
or to have a static method to process the input String.
Explanation: Spring IoC container will try to instantiate a new InputItemReader object like this :
new InputItemReader( -- WHAT TO PUT HERE? --)
and will fail to call your constructor, because it will not know what you do actually expect and input string.
UPDATE: Your problem can be solved by removing @Component annotation and defining the bean in a configuration like this:
@Bean
public InputItemReader inputItemReader(InputFileHeaderValidator inputFileHeaderValidator, FileAuditService fileAuditService){
InputItemReader inputItemReader = new InputItemReader("--HERE SHOULD BE ACTUAL PATH---");
// set the required service, a cleaner approach would be to send them via constructor
inputItemReader.setFilteAuditService(fileAuditService);
inputItemReader.setInputFileHeaderValidator(inputFileHeaderValidator);
return inputItemReader;
}