Spring Integration 3.0下面的代码在Spring 3.0中成功运行。
但是,在升级到Spring 3.2时,它会抛出2个以下的例外:
org.springframework.expression.AccessException: Unable to access property 'messages' through getter
java.lang.IllegalStateException: Invalid method parameter for messages: was expecting a single payload.
<int-jdbc:inbound-channel-adapter
query="select ..."
channel="inp" data-source="dataSource"
<int:poller fixed-rate="2000">
</int:poller>
</int-jdbc:inbound-channel-adapter>
以上查询返回一行或多行,结果分配给List of Service Activator
<int:service-activator input-channel="inp" ref="FileService" output-channel="resp" />
@ServiceActivator(inputChannel = "inp", outputChannel = "resp")
public List<?> process(List<?> ) {
...
}
在Spring 3.2中获得以下异常。
10:15:44.556 DEBUG [task-scheduler-1][org.springframework.integration.channel.PublishSubscribeChannel] preSend on channel 'errorChannel', message: [Payload=org.springframework.integration.MessageHandlingException: org.springframework.expression.AccessException: Unable to access property 'messages' through getter][Headers={timestamp=1402409744556, id=a5143a74-7da4-d745-bda5-2a74ce102491}]
10:15:44.556 DEBUG [task-scheduler-1][org.springframework.integration.handler.LoggingHandler] (inner bean)#d72200 received message: [Payload=org.springframework.integration.MessageHandlingException: org.springframework.expression.AccessException: Unable to access property 'messages' through getter][Headers={timestamp=1402409744556, id=a5143a74-7da4-d745-bda5-2a74ce102491}]
10:15:44.559 ERROR [task-scheduler-1][org.springframework.integration.handler.LoggingHandler] org.springframework.integration.MessageHandlingException: org.springframework.expression.AccessException: Unable to access property 'messages' through getter
at org.springframework.integration.handler.MethodInvokingMessageProcessor.processMessage(MethodInvokingMessageProcessor.java:76)
at org.springframework.integration.handler.ServiceActivatingHandler.handleRequestMessage(ServiceActivatingHandler.java:67)
at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:142)
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:73)
at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:115)
at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:102)
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:178)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:149)
at org.springframework.integration.core.MessagingTemplate.doSend(MessagingTemplate.java:330)
at org.springframework.integration.core.MessagingTemplate.send(MessagingTemplate.java:169)
at org.springframework.integration.endpoint.SourcePollingChannelAdapter.handleMessage(SourcePollingChannelAdapter.java:97)
at org.springframework.integration.endpoint.AbstractPollingEndpoint.doPoll(AbstractPollingEndpoint.java:199)
at org.springframework.integration.endpoint.AbstractPollingEndpoint.access$000(AbstractPollingEndpoint.java:51)
at org.springframework.integration.endpoint.AbstractPollingEndpoint$1.call(AbstractPollingEndpoint.java:143)
at org.springframework.integration.endpoint.AbstractPollingEndpoint$1.call(AbstractPollingEndpoint.java:141)
at org.springframework.integration.endpoint.AbstractPollingEndpoint$Poller$1.run(AbstractPollingEndpoint.java:273)
at org.springframework.integration.util.ErrorHandlingTaskExecutor$1.run(ErrorHandlingTaskExecutor.java:52)
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:49)
at org.springframework.integration.util.ErrorHandlingTaskExecutor.execute(ErrorHandlingTaskExecutor.java:49)
at org.springframework.integration.endpoint.AbstractPollingEndpoint$Poller.run(AbstractPollingEndpoint.java:268)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:53)
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(Unknown Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.expression.AccessException: Unable to access property 'messages' through getter
at org.springframework.expression.spel.support.ReflectivePropertyAccessor$OptimalPropertyAccessor.read(ReflectivePropertyAccessor.java:614)
at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:202)
at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:85)
at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:78)
at org.springframework.expression.spel.ast.MethodReference.getArguments(MethodReference.java:147)
at org.springframework.expression.spel.ast.MethodReference.getValueRef(MethodReference.java:66)
at org.springframework.expression.spel.ast.CompoundExpression.getValueRef(CompoundExpression.java:63)
at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:82)
at org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:102)
at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:103)
at org.springframework.integration.util.AbstractExpressionEvaluator.evaluateExpression(AbstractExpressionEvaluator.java:144)
at org.springframework.integration.util.MessagingMethodInvokerHelper.processInternal(MessagingMethodInvokerHelper.java:268)
at org.springframework.integration.util.MessagingMethodInvokerHelper.process(MessagingMethodInvokerHelper.java:142)
at org.springframework.integration.handler.MethodInvokingMessageProcessor.processMessage(MethodInvokingMessageProcessor.java:73)
... 30 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.expression.spel.support.ReflectivePropertyAccessor$OptimalPropertyAccessor.read(ReflectivePropertyAccessor.java:610)
... 43 more
Caused by: java.lang.IllegalStateException: Invalid method parameter for messages: was expecting a single payload.
at org.springframework.util.Assert.state(Assert.java:385)
at org.springframework.integration.util.MessagingMethodInvokerHelper$ParametersWrapper.getMessages(MessagingMethodInvokerHelper.java:788)
... 48 more
编辑:根据日志的有效负载和标头
[Payload=[{NID=1241430 , CTR=0 , FLAG=01, UPDATETIME=2013-08-12 07:42:35.137}, {NID=1241430 , CTR=001 , FLAG=01, UPDATETIME=2013-08-12 07:42:35.457}]][Headers={timestamp=1402472659515, id=a08ec480-1356-001b-e6f7-0511b9ecf6d6}]
答案 0 :(得分:0)
我认为将method="process"
添加到<service-activator>
可以解决问题。
假设您的FileService
有多种方法,对于框架,如果它们不与消息规则一起使用,则很难确定每种情况使用哪种方法。
<强>更新强>
实际上<int-jdbc:inbound-channel-adapter>
会返回List<?>
,与行数无关。您的process(List<?> )
看起来应该更适合列表的通用类型,因为您的有效负载是List<Object>
,而不是List<Message<?>>
。
MessagingMethodInvokerHelper
为messages
评估上下文根对象构建表达式时有两种情况:
if (annotationType.equals(Payloads.class)) {
sb.append("messages.![payload");
else if ((parameterTypeDescriptor.isAssignableTo(messageListTypeDescriptor) || parameterTypeDescriptor
.isAssignableTo(messageArrayTypeDescriptor))) {
sb.append("messages");
我认为你的问题在于seocnd问题。从3.2开始,TypeDescriptor
在Spring中发生了一些变化。