For example, if you want to create a class that represents a Chunk-oriented Tasklet, you might want to define a class that holds FlatFileItemReaderBuilder
, ʻItemProcessor,
JdbcBatchItemWriterBuilder`.
However, even if this class is registered as Bean
, JdbcBatchItemWriterBuilder
will not operate normally with the following error.
Output error
org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [INSERT INTO people (first_name, last_name) VALUES (:firstName, :lastName)]; nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException:SQL statement has syntax error"INSERT INTO PEOPLE (FIRST_NAME, LAST_NAME) VALUES (:[*]FIRSTNAME, :LASTNAME)";Expected statement"), DEFAULT, NOT, EXISTS, INTERSECTS, UNIQUE"
Syntax error in SQL statement "INSERT INTO PEOPLE (FIRST_NAME, LAST_NAME) VALUES (:[*]FIRSTNAME, :LASTNAME)"; expected "), DEFAULT, NOT, EXISTS, INTERSECTS, UNIQUE"; SQL statement:
For some reason : firstName
has not been converted to?
.
(Of course, if you register JdbcBatchItemWriterBuilder
directly as Bean
, it works fine.)
When all beans are registered, registration is completed normally by calling ʻafterPropertiesSet () for classes that have ʻInitializingBean
ʻimplements`.
However, if you have nested objects that should be beans, they will not be called and registration will not be completed normally.
Implement ʻInitializingBeanin the holding parent class (= class exposed directly as
Bean`) and propagate it to the holding object.
@Override
public void afterPropertiesSet() throws Exception {
Object[] objects = new Object[]{this.reader, this.processor, this.writer};
for (Object object : objects) {
if (object instanceof InitializingBean) {
((InitializingBean) object).afterPropertiesSet();
}
}
}
Recommended Posts