我试图每5秒轮询一次数据库,并希望获得过去5秒内创建/更新的所有记录。
这是代码块
@Bean
public JpaExecutor jpaExecutor() {
JpaExecutor executor = new JpaExecutor(this.entityManagerFactory);
executor.setJpaQuery("from Product p where p.updateDttm >= :updateDttm");
executor.setJpaParameters(Collections.singletonList(new JpaParameter("updateDttm", "2019-02-28 12:02:15.000", null)));
return executor;
}
这是我遇到的错误
ERROR 908 --- [ask-scheduler-8] o.s.integration.handler.LoggingHandler : org.springframework.messaging.MessagingException: nested exception is java.lang.IllegalArgumentException: Query has parameters but no parameter source provided
at org.springframework.integration.endpoint.AbstractPollingEndpoint.pollForMessage(AbstractPollingEndpoint.java:343)
at org.springframework.integration.endpoint.AbstractPollingEndpoint.lambda$null$1(AbstractPollingEndpoint.java:277)
at org.springframework.integration.util.ErrorHandlingTaskExecutor.lambda$execute$0(ErrorHandlingTaskExecutor.java:57)
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
at org.springframework.integration.util.ErrorHandlingTaskExecutor.execute(ErrorHandlingTaskExecutor.java:55)
at org.springframework.integration.endpoint.AbstractPollingEndpoint.lambda$createPoller$2(AbstractPollingEndpoint.java:274)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:93)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalArgumentException: Query has parameters but no parameter source provided
at org.springframework.integration.jpa.core.DefaultJpaOperations.setParametersIfRequired(DefaultJpaOperations.java:348)
at org.springframework.integration.jpa.core.DefaultJpaOperations.getQuery(DefaultJpaOperations.java:117)
at org.springframework.integration.jpa.core.DefaultJpaOperations.getResultListForQuery(DefaultJpaOperations.java:190)
at org.springframework.integration.jpa.core.JpaExecutor.doPoll(JpaExecutor.java:569)
at org.springframework.integration.jpa.core.JpaExecutor.poll(JpaExecutor.java:505)
at org.springframework.integration.jpa.core.JpaExecutor.poll(JpaExecutor.java:476)
at org.springframework.integration.jpa.inbound.JpaPollingChannelAdapter.doReceive(JpaPollingChannelAdapter.java:82)
at org.springframework.integration.endpoint.AbstractMessageSource.receive(AbstractMessageSource.java:160)
at org.springframework.integration.endpoint.SourcePollingChannelAdapter.receiveMessage(SourcePollingChannelAdapter.java:250)
at org.springframework.integration.endpoint.AbstractPollingEndpoint.doPoll(AbstractPollingEndpoint.java:360)
at org.springframework.integration.endpoint.AbstractPollingEndpoint.pollForMessage(AbstractPollingEndpoint.java:329)
答案 0 :(得分:1)
您的执行最终会遵循以下逻辑:
if (requestMessage == null) {
result = doPoll(this.parameterSource, 0, maxNumberOfResults);
}
您似乎没有配置this.parameterSource
的地方。
可以通过以下方式进行配置:
/**
* Specify the {@link ParameterSource} that would be used to provide
* additional parameters.
* @param parameterSource Must not be null.
*/
public void setParameterSource(ParameterSource parameterSource) {
但是,如果偏爱executor.setJpaParameters
上的二传手,则需要放弃该BeanPropertyParameterSourceFactory.setStaticParameters()
。 createParameterSource(null)
可用于在
setParameterSource()
。
我认为我们可以考虑在此问题上进行一些改进,以在内部构建JpaExecutor
进行轮询,就像在进行出站操作时为ParameterSource
所做的那样。
随时可以就此事提出GH问题。