[JAVA] How to solve the problem that it is not processed normally when nesting beans in Spring Batch

Overview

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.)

Cause

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.

Solution

Implement ʻInitializingBeanin the holding parent class (= class exposed directly asBean`) 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

How to solve the problem that it is not processed normally when nesting beans in Spring Batch
How to solve the problem when the value is not sent when the form is disabled in rails and sent
How to solve the problem that the website image is not displayed after deploying to heroku on Rails 5
[Rails] How to solve the problem that the default image is overwritten when editing without uploading the image [Active Storage]
How to set when "The constructor Empty () is not visible" occurs in junit
How to fix the problem that the upper half is cut off when using UITabBar
I want to solve the problem that JS is not displayed properly unless reloaded when transitioning with Turbolinks: link_to
How to solve the problem that line breaks in cells are amplified when outputting EXCEL using SXSSF Workbook (3.16 or older)
How to fix the problem that Aptana Studio does not start
How to output the value when there is an array in the array
How to solve the unknown error when using slf4j in Java
How to write the view when Vue is introduced in Rails?
How to solve the problem that you can not pull image from docker hub with Minikube
About the solution to the problem that the log of logback is not output when the web application is stopped
How to solve the problem that notification cannot be requested on iOS14
How to constrain the action of the transition destination when not logged in
How to not start Flyway when running unit tests in Spring Boot
[Ruby] How to prevent errors when nil is included in the operation
How to resolve the error'ActionView :: Template :: Error (The asset "application.css" is not present in the asset pipeline.'" When precompiling Rails assets
How to solve an Expression Problem in Java
Is it mainstream not to write the closing tag of <P> tag in Javadoc?
When the project is not displayed in eclipse
[Swift] How to simply describe dismiss that was not taught in the introductory book
Processing when an ID that does not exist in the database is entered in the URL
How to use CommandLineRunner in Spring Batch of Spring Boot
When Spring Batch is executed continuously in Oracle, ORA-08177
How to use In-Memory Job repository in Spring Batch
Fixed the phenomenon that vuetify built in Rails is not loaded when page transition is done
How to batch initialize arrays in Java that I didn't know when I was a beginner
Use cryptographically secure pseudo-random numbers to verify that the solution to the Monty Hall problem is not 50%
[Spring Dtata JPA] How to deal with the problem that DB change cannot be detected when you want to process API synchronously with a single thread in Spring Boot.
How to set chrony when the time shifts in CentOS7
How to get the log when install4j does not start
[Rails] How to temporarily save the request URL of a user who is not logged in and return to that URL after logging in
Throw an exception and catch when there is no handler corresponding to the path in spring
Lenovo ThinkPad T14 Gen1 How to solve the problem that the speaker becomes dummy and cannot be used when installing Ubuntu 20.04 on AMD
About the problem that the image is not displayed after AWS deployment
ProxyFactory is convenient when you want to test AOP in Spring!
Solved the problem that the scroll event did not fire in JQuery
Like function The part that is stuck in making it asynchronous
What to do when the changes in the Servlet are not reflected
[jOOQ] How to CASE WHEN in the WHERE / AND / OR clause
How to identify the path that is easy to make a mistake
[RSpec] When you want to use the instance variable of the controller in the test [assigns is not recommended]
An active hash that can be treated as data even if it is not in the database
What to do if Operation not permitted is displayed when you execute a command in the terminal
How to use Lombok in Spring
How to interact with a server that does not crash the app
What to do if the prefix c is not bound in JSP
[Docker] How to solve the error function not implemented @ io_fread ~ [Super easy]
[Rails] About the error that the image is not displayed in the production environment
I tried to solve the tribonacci sequence problem in Ruby, with recursion.
[Docker] How to build when the source code is bind-mounted on the container
How to find the total number of pages when paging in Java
How to get the value after "_" in Windows batch like Java -version
How to get the setting value (property value) from the database in Spring Framework
Is it possible to put the library (aar) in the Android library (aar) and use it?
How to reference a column when overriding the column name method in ActiveRecord
JSESSIONID could not be assigned to the URL when using Spring Security
The problem that the localhost page launched by Docker cannot be confirmed in the browser when the ESET firewall is operating
Continuation ・ Active hash that can be handled as data even if it is not in the database ~ Display