jpa inbound-channel-adapter不支持参数源

时间:2015-07-08 19:40:34

标签: spring-integration

我正在尝试使用参数源为入站通道适配器中的查询提供参数,但它似乎不起作用。我查看了Parser代码,我认为它不处理参数源代码。

<int-jpa:inbound-channel-adapter delete-after-poll="true"
    delete-in-batch="true" auto-startup="true" flush-after-delete="true"
    max-results="2000"
    entity-manager-factory="entityManagerFactory"
    entity-class="AuditMessage"
    channel="processMessage"
    jpa-query="select a from AuditMessage a where a.updateTs &lt; :purgeDate"
    parameter-source="parameterSource">
    <int:poller cron="*/5 * * * * *" >
        <int:transactional transaction-manager="transactionManager"/>
    </int:poller>
</int-jpa:inbound-channel-adapter>

<bean id="parameterSource" factory-bean="spelSource"
            factory-method="createParameterSourceNoCache">
    <constructor-arg value="" />
</bean>

<bean id="spelSource"
    class="org.springframework.integration.jdbc.ExpressionEvaluatingSqlParameterSourceFactory">
    <property name="parameterExpressions">
        <map>
            <entry key="purgeDate"
                value="new java.sql.Timestamp(T(System).currentTimeMillis()-(T(java.util.concurrent.TimeUnit).MILLISECONDS.convert(${eam.integration.arcgis.purge.daysToKeep}, T(java.util.concurrent.TimeUnit).DAYS)))" />
        </map>
    </property>
</bean>

我得到以下异常:

ERROR [task-scheduler-9] [java.lang.IllegalArgumentException: Query has parameters but no parameter source provided
at org.springframework.integration.jpa.core.DefaultJpaOperations.setParametersIfRequired(DefaultJpaOperations.java:330)
at org.springframework.integration.jpa.core.DefaultJpaOperations.getQuery(DefaultJpaOperations.java:114)
at org.springframework.integration.jpa.core.DefaultJpaOperations.getResultListForQuery(DefaultJpaOperations.java:186)
at org.springframework.integration.jpa.core.JpaExecutor.doPoll(JpaExecutor.java:396)...

我在春季版4.0.3。难道我做错了什么?或者是否有另一种提供查询参数的方法?

1 个答案:

答案 0 :(得分:1)

我认为您刚刚发现了一个错误!

JpaInboundChannelAdapterParser只是不解析parameter-source attrbiute。随意提出一个JIRA错误。

作为一种变通方法,您必须将JpaPollingChannelAdapter配置为原始<bean>并注入JpaExecutor,并将其用作来自通用ref的{​​{1}}。

JIRA ticket适合那些想要跟踪的人。