我无法让ExpressionEvaluatingRequestHandlerAdvice类在Spring Integration 4.1.x中运行。以下表达式建议上下文XML片段生成转换错误,指出Spring无法将属性onSuccessExpression转换为String中的表达式。在Spring Integration 4.1.0-RELEASE之前,setOnSuccessExpression()方法只接受字符串,现在它被重载以接受字符串或表达式。
<sftp:outbound-channel-adapter channel="outboundChannel"
session-factory="sftpCachingSessionFactory" remote-directory="${sftp.remote.file.location.path}"
temporary-file-suffix=".tmp">
<sftp:request-handler-advice-chain>
<bean
class="org.springframework.integration.handler.advice.RequestHandlerRetryAdvice">
<property name="retryTemplate" ref="defaultRetryTemplate" />
</bean>
<bean
class="org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice">
<property name="onSuccessExpression" value="headers.ID" />
<property name="successChannel" ref="outboundSuccessChannel" />
</bean>
</sftp:request-handler-advice-chain>
</sftp:outbound-channel-adapter>
以下是显示的错误:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.file.config.FileWritingMessageHandlerFactoryBean#0': Cannot resolve reference to bean 'org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice#7d12855' while setting bean property 'adviceChain' with key [1]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice#7d12855' defined in class path resource [file-transfer-service-file-endpoint-context.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.lang.String' to required type 'org.springframework.expression.Expression' for property 'onSuccessExpression'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [org.springframework.expression.Expression] for property 'onSuccessExpression': no matching editors or conversion strategy found
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:382)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:157)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1469)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:743)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at pmd.common.spring.SpringServiceContextLoader.main(SpringServiceContextLoader.java:63)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice#7d12855' defined in class path resource [file-transfer-service-file-endpoint-context.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.lang.String' to required type 'org.springframework.expression.Expression' for property 'onSuccessExpression'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [org.springframework.expression.Expression] for property 'onSuccessExpression': no matching editors or conversion strategy found
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)
... 15 more
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.lang.String' to required type 'org.springframework.expression.Expression' for property 'onSuccessExpression'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [org.springframework.expression.Expression] for property 'onSuccessExpression': no matching editors or conversion strategy found
at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:475)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:511)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:505)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1515)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1474)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
... 21 more
Caused by: java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [org.springframework.expression.Expression] for property 'onSuccessExpression': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:287)
at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:460)
... 27 more
我的问题是我不认为我的onSuccessExpression应该被转换,在setOnSuccessExpression()方法上有一个字符串的setter。是否有我的修复或Spring Int创建了一个错误?
答案 0 :(得分:2)
这是一个错误;我们添加了第二组setter来支持DSL(所以你可以注入一个String或Expression)。
问题在于违反了JavaBean定义(具有不同参数类型的2个setter),所以Spring并不知道要选择哪个。我们需要更改方法名称。
不幸的是,对于Spring调用哪种方法,它是不确定的。
与此同时,您可以尝试解决这个问题......
<bean id="success" class="org.springframework.integration.config.ExpressionFactoryBean">
<constructor-arg value="headers.ID" />
</bean>
和...
<property name="onSuccessExpression" ref="success" />
不幸的是,它不确定调用哪个方法;在我的环境中,您的代码可以正常工作,因为选择了方法的String版本。
因此,如果您在多个环境中运行,则可能必须将建议作为@Bean
连接起来。
我打开了JIRA Issue。我们很快就会在发布中获得修复。