我有一个Spring集成应用程序,用于轮询来自AS400 DB的数据,然后经过一些修改后将其传输到MQ。
它运行正常,直到我决定升级Spring Integration版本
从版本 - spring-integration-core-2.2.3.RELEASE
升级到spring-integration-core-3.0.1.RELEASE
后,我收到以下错误。
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [tcm-hosttrade-inbound-adapter.xml]; nested exception is java.lang.ClassCastException: org.springframework.beans.factory.config.RuntimeBeanReference cannot be cast to org.springframework.beans.factory.config.BeanDefinition
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:412)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.importBeanDefinitionResource(DefaultBeanDefinitionDocumentReader.java:250)
... 21 more
Caused by: java.lang.ClassCastException: org.springframework.beans.factory.config.RuntimeBeanReference cannot be cast to org.springframework.beans.factory.config.BeanDefinition
at org.springframework.integration.config.xml.AbstractPollingInboundChannelAdapterParser.doParse(AbstractPollingInboundChannelAdapterParser.java:50)
at org.springframework.integration.config.xml.AbstractChannelAdapterParser.parseInternal(AbstractChannelAdapterParser.java:66)
at org.springframework.beans.factory.xml.AbstractBeanDefinitionParser.parse(AbstractBeanDefinitionParser.java:59)
at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:73)
at org.springframework.integration.config.xml.AbstractIntegrationNamespaceHandler.parse(AbstractIntegrationNamespaceHandler.java:94)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1438)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1428)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:195)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:139)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:108)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)
... 26 more
我检查了类的代码 - org.springframework.integration.config.xml.AbstractPollingInboundChannelAdapterParser
我刚发现这3行代码与早期版本不同 -
String channelAdapterId = this.resolveId(element, adapterBuilder.getRawBeanDefinition(), parserContext);
String sourceBeanName = channelAdapterId + ".source";
parserContext.getRegistry().registerBeanDefinition(sourceBeanName, (BeanDefinition) source);
错误是因为这一行 - parserContext.getRegistry()。registerBeanDefinition(sourceBeanName,(BeanDefinition)source);
如何使此代码正常工作?以下是我的豆子,可供参考 -
入站通道Bean -
<inbound-channel-adapter id="inboundAdapter"
ref="readFromMessageStore"
channel="inboundChannel" auto-startup="false" />
答案 0 :(得分:2)
是的,3.0.1
版本存在问题。它已在3.0.2
版本中得到解决。您可以查看此链接了解详情:https://jira.spring.io/browse/INT-3300。
页面链接中的小摘要:
Summary Class cast exception using DefaultInboundChannelAdapterParser
Regression: Class cast exception using DefaultInboundChannelAdapterParser Fix Version/s 3.0.2 [ 14362 ] Fix Version/s 4.0 M4 [ 14361 ] Affects Version/s 3.0.1 [ 14309 ]
答案 1 :(得分:0)
升级到新版本时,通常建议使用该行中的最新版本;当您在该行中的最新版本为3.0.1
时,我对您选择3.0.7
的原因感到好奇。当前版本为4.1.5
;有关完整版本信息,请参阅the project page。通常,点发布(3.0.2,3.0.3等)仅包含错误修复。另外,请注意migration guides。