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
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;
}