【发布时间】:2014-06-05 15:51:35
【问题描述】:
请看链接:
Spring Integration: Inbound-channel-adapter update query parameter exception when using RowMapper
我正在做类似的配置,但不确定如何将行映射器与拆分器一起使用。
我正在尝试创建一个 db-poller 并希望使用 row-mapper 在 service-activator 中接收传入的行,但消息没有到达那里..
这是我的配置。请指教。
我的配置:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-jdbc="http://www.springframework.org/schema/integration/jdbc"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration/jdbc http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc-3.0.xsd">
<context:component-scan base-package="com.checkfree.isolutions" />
<int-jdbc:inbound-channel-adapter id="invoiceInbound" query="select * from invoice where status = '0'" auto-startup="true"
channel="invoiceInboundChannel" data-source="dataSource" row-mapper="rowMapper"
update="update invoice set status = 'PROCESSED' where id in (:id) " max-rows-per-poll="1">
<int:poller max-messages-per-poll="1" fixed-rate="10000">
<int:transactional transaction-manager="transactionManager"
isolation="DEFAULT"
propagation="REQUIRED"
read-only="false"
timeout="1000"/>
</int:poller>
</int-jdbc:inbound-channel-adapter>
<!-- Add RowMapper tag : row-mapper="rowMapper" -->
<bean id="rowMapper" class="com.checkfree.isolutions.InvoiceMapper"></bean>
<int:chain input-channel="invoiceInboundChannel" output-channel="filteredChannel">
<int:splitter ref="invoiceSplitter" />
</int:chain>
<int:channel id="filteredChannel" />
<int:service-activator id="taskActivator" input-channel="filteredChannel" ref="taskCreator" method="processInvoice">
</int:service-activator>
</beans>
这是我的服务激活器:
@Component("taskCreator")
public class TaskCreator {
static Logger logger = Logger.getLogger(TaskCreator.class.getName());
@Autowired
InvoiceService invoiceService;
@Transactional(readOnly = false)
public void processInvoice(Object invoiceObj) throws Exception {
System.out.println("row received.." + invoiceObj.getClass().getCanonicalName());
}
}
我无法在控制台中看到打印消息“row received..”。
但在调试 rowmapper 中,每次调用都会调用 mapRow 方法。
public class InvoiceMapper implements RowMapper {
@Override
public Invoice mapRow(ResultSet rs, int rowNum) throws SQLException {
Invoice invoice = new Invoice();
--
--
}
}
我想要实现的是我的 TaskCreator 应该以行映射器 (InvoiceMapper) 格式接收传入的表行。
我刚刚更正了我的配置。
当我打开调试时,我可以看到控制权转到 RowMapper。
问题:我不知道如何将 row-mapper 与 spiltter 一起使用。谁能举个例子..
你能不能给点建议。提前谢谢..
问候,希夫
【问题讨论】:
-
invoiceSplitter看起来像什么?打开 DEBUG 日志记录并通过渠道 (preSend, postSend) 跟踪消息。 -
加里,感谢您的回复。我已经更正了我的配置。我可以使用 invoicesplitter 接收消息(如果我删除 row-mapper 属性)。当我添加行映射器属性时,不会调用 processInvoice。在调试模式下,我可以看到控制转到行映射器类,但控制永远不会转到 TastCreate(服务激活器)类。所以如果我减去行映射器条目,那么我的代码工作得很好。但是当我添加一些 JDBC 特定转换所需的行映射器时。然后控制永远不会转到服务激活器类。
标签: java spring spring-integration spring-jdbc