Spring 如何将日志添加到jdbc pollar适配器

Spring 如何将日志添加到jdbc pollar适配器,spring,spring-integration,Spring,Spring Integration,我正在尝试实现BeanPostProcessor以返回我自己的JdbcPollingChannelAdapter,这将帮助我添加一些日志记录并了解轮询活动。我有一些代码在下面,请帮助完成这一点,或者如果有更好的方法 谢谢 public class CustomAdapter extends JdbcPollingChannelAdapter { private final static Logger logger = LoggerFactory.getLogger(CustomAdapter

我正在尝试实现BeanPostProcessor以返回我自己的JdbcPollingChannelAdapter,这将帮助我添加一些日志记录并了解轮询活动。我有一些代码在下面,请帮助完成这一点,或者如果有更好的方法

谢谢

public class CustomAdapter extends JdbcPollingChannelAdapter {

private final static Logger logger = LoggerFactory.getLogger(CustomAdapter .class);

public CustomJdbcPollingChannelAdapter(DataSource dataSource, String selectQuery)
{
    super(dataSource, selectQuery);        
}

@Override
public Message<Object> receive()
{
    Message<Object> polledData =  super.receive();
    if(polledData == null || polledData.getPayload() == null)
    logger.info("received no data..............");
    return polledData;

}
}

JdbcPollingChannelAdapter是一个消息源,它是一个从活动端点-SourcePollingChannelAdapter使用的组件,该组件具有以下代码:

if (message == null) {
    if (this.logger.isDebugEnabled()){
        this.logger.debug("Received no Message during the poll, returning 'false'");
    }
    result = false;
}
else {
    if (this.logger.isDebugEnabled()){
            this.logger.debug("Poll resulted in Message: " + message);
    }
    if (holder != null) {
        holder.setMessage(message);
    }
    this.handleMessage(message);
    result = true;
}
那么,仅仅配置org.springframework.integration.endpoint.SourcePollingChannelAdapter日志类别还不够吗

从另一方面来说,使用自定义MessageSource实现是不停的,BeanPostProcessor实际上是一种开销。您只需要将CustomAdapter配置为泛型,并从另一个泛型bean定义SourcePollingChannelAdapterFactoryBean中使用它

没错,通过这种定制,您将失去Spring集成XML的能力。但是谁说XML是万灵药呢

更新

由于您有一个自定义消息源,因此可以直接从以下位置使用它:

<bean id="jdbcSource" class="com.my.proj.adapter.CustomAdapter">
   <constructor-arg ref="dataSource"/>
   <constructor-arg value="SELECT * FROM foo"/>
   <property name="updateSql" value="UPDATE foo set status=1 where id in (:id)"/>
</bean>

<int:inbound-channel-adapter ref="jdbcSource" channel="jdbcPollingChannel"/>

任何特定协议都只是为了方便起见,但它们都与默认协议相同。

日志级别没有帮助,因为我有几个轮询适配器正在运行,为了帮助支持/监控此应用程序,我需要记录组件的名称等。我可以将其作为通用协议使用,但它是否允许我使用轮询适配器的其他功能,事务和更新sql?这无关紧要:Spring Integration XML被解析并填充为bean,例如,填充JdbcPollingChannelAdapter和SourcePollingChannelAdapter以从第一个开始进行轮询。您能否给出一个示例或提示,我如何将添加的示例替换为应答批准应答!:-
<bean id="jdbcSource" class="com.my.proj.adapter.CustomAdapter">
   <constructor-arg ref="dataSource"/>
   <constructor-arg value="SELECT * FROM foo"/>
   <property name="updateSql" value="UPDATE foo set status=1 where id in (:id)"/>
</bean>

<int:inbound-channel-adapter ref="jdbcSource" channel="jdbcPollingChannel"/>