【发布时间】:2018-02-22 05:55:10
【问题描述】:
我的 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。
我错过了什么?
【问题讨论】:
-
可能是默认测试框架的回滚性质?
-
我没有写任何测试代码。 ApplicationTests 类只有一个空的 contextLoads 方法。我只是运行
mvn spring-boot:run -
请打开
org.springframework.jdbc类别的调试日志记录,以调查对您的数据库调用的内容和方式。如果您通过 Maven 运行您的应用程序,不确定如何检查嵌入式数据库的状态... -
我在 pom.xml 中有 spring-boot-starter-web 依赖项,在 application.properties 中有 spring.h2.console.enabled=true。我在 localhost:8080/h2-console/ 检查数据库虽然我添加了调试日志记录,但我仍然没有从消息中得到任何帮助。
-
好的!有没有机会从您那里获得一个简单的 Spring Boot 项目,让我们在本地使用它来理解问题?谢谢