user1575148
user1575148

Reputation: 589

Spring Integration JDBC inbound channel adapter not updating records

The application context of my Spring Boot application is:

<context:component-scan
base-package="org.mycompany.myproject.polling" />

<int:channel id="fromdb" />
<jdbc:embedded-database id="dataSource" type="H2" />
<int:service-activator input-channel="fromdb" ref="jdbcMessageHandler" />
<int-jdbc:inbound-channel-adapter
    channel="fromdb" data-source="dataSource"
    query="select * from Books where status = 0"
    update="update Books set status = 1">
    <int:poller fixed-delay="1000"/>
</int-jdbc:inbound-channel-adapter>

I have schema.sql and data.sql in the resources directory that create the table and insert data on startup with all records in the status column having value 0. The update query of the inbound channel adapter does not run, since I see that status column in H2 still has value 0.

What did I miss?

Upvotes: 0

Views: 862

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121262

Your application works for me well after this simple modifications:

@SpringBootApplication
@ImportResource("application-context.xml")
public class DbpollerApplication {

    public static void main(String[] args) {
        SpringApplication.run(DbpollerApplication.class, args);
    }

}

As you see I removed suspicious code for the ClassPathXmlApplicationContext and really let Spring Boot to load everything, including Embedded DataSource.

In the application-context.xml I removed <context:component-scan> and <jdbc:embedded-database> just because they are supplied by the Spring Boot per se.

After starting application I see in logs:

Row
column: ITEM_ID value: Book_id99
column: DESCRIPTION value: Book_description99
column: STATUS value: 0
Row
column: ITEM_ID value: XXX
column: DESCRIPTION value: last book
column: STATUS value: 0

And also I've copied from there and URL to the DB:

2018-02-21 16:49:40.357  INFO 10576 --- [           main] o.s.j.d.e.EmbeddedDatabaseFactory        : Starting embedded database: url='jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false', username='sa'

The part jdbc:h2:mem:testdb is just enough.

Then I've opened H2 Web console on the localhost:8080/h2-console, connected to the mentioned URL and did a SELECT from the BOOKS table and got this result:

enter image description here

Am I missing anything?

Upvotes: 1

Related Questions