Spring Integration JDBC入站通道适配器不更新记录

时间:2018-02-19 18:13:53

标签: spring-integration

我的Spring Boot应用程序的应用程序上下文是:

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

我在资源目录中有schema.sql和data.sql,它们创建表并在启动时插入数据,状态列中的所有记录的值都为0.入站通道适配器的更新查询不会运行,因为我看到H2中的状态列仍然具有值0。

我错过了什么?

1 个答案:

答案 0 :(得分:1)

经过这些简单的修改后,您的申请对我很有用:

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

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

}

如您所见,我删除了ClassPathXmlApplicationContext的可疑代码,并让Spring Boot加载所有内容,包括Embedded DataSource。

application-context.xml我删除了<context:component-scan><jdbc:embedded-database>只是因为它们是由Spring Boot本身提供的。

启动应用程序后,我在日志中看到:

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

我也从那里复制并将URL复制到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'

部分jdbc:h2:mem:testdb就足够了。

然后我在localhost:8080/h2-console上打开了H2 Web控制台,连接到提到的网址,并从SELECT表格中获得了BOOKS并获得了此结果:

enter image description here

我错过了什么吗?