Reputation: 157
Consider defining a bean of type 'java.lang.String' in your configuration. is the error I get with the following reader method:
@Bean
public JdbcCursorItemReader<Assessment> getReader(DataSource datasource, String query, String name) {
return new JdbcCursorItemReaderBuilder<Assessment>()
.dataSource(datasource)
.sql(query)
.name(name)
.rowMapper(new AssessmentMapper())
.build();
}
Where the step config looks like :
public Step step1(StepBuilderFactory factory,
DataSource dataSource,
ItemReader reader,
ExpireAssessmentWriter writer, //use custom writer
AssessmentItemProcessor processor,
PlatformTransactionManager platformTransactionManager){
return stepBuilderFactory.get("step1")
.transactionManager(platformTransactionManager)
.<Assessment,Assessment>chunk(10)
.reader(getReader(dataSource, READER_QUERY, "AssessmentReader"))
.processor(processor)
.writer(writer)
.build();
}
Why am i getting an error when trying to pass a string to getReader?
EDIT: The error comes from the second parameter in getReader. I am just trying to pass the query as a string but the Error output looks like:
Description:
Parameter 0 of method getReader in com.batch.config.ExpirationUtilityConfig required a bean of type 'java.lang.String' that could not be found.
Action:
Consider defining a bean of type 'java.lang.String' in your configuration.
Upvotes: 1
Views: 679
Reputation: 31710
You need to remove @Bean
on getReader()
. Since you are calling getReader
in your step definition, you don't need to declare the reader as a Spring bean.
You need to remove the ItemReader from the parameters list of your step definition as well.
Upvotes: 2