我正在为我的项目使用Spring-Integration。我正在尝试从xml文件(而不是.properties文件)中读取属性/常量值。我在其中放置属性/常量的xml文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<persistence>
<dataSourceName>CS/PowerSTEPP_CSSTEPPQA</dataSourceName>
</persistence>
<customerservice>
<headerNames>
<jobName>jobDesignerJobName</jobName>
</headerNames>
<headerNames>
<originalPayload>originalPayload</originalPayload>
</headerNames>
<headerNames>
<originalPayloadDuplicate>originalPayload</originalPayloadDuplicate>
</headerNames>
<headerNames>
<legacySystem>legacySystem</legacySystem>
</headerNames>
<headerNames>
<businessArea>businessArea</businessArea>
</headerNames>
<routing>
<jobChannel>headers.jobDesignerJobName+'-InputChannel'</jobChannel>
</routing>
<routing>
<jobErrorChannel>headers.jobDesignerJobName+'-XsltTransformInputChannel'</jobErrorChannel>
</routing>
<legacySystem>
<powerstepp>PowerSTEPP</powerstepp>
</legacySystem>
<PQProviderSearch>
<storedProcedureName>PQPRVSCH</storedProcedureName>
</PQProviderSearch>
<PQProviderSearch>
<ROWREQ>00001</ROWREQ>
</PQProviderSearch>
<PQProviderSearch>
<DBGFLG>Y</DBGFLG>
</PQProviderSearch>
<PQProviderSearch>
<SECDAT></SECDAT>
</PQProviderSearch>
<stylesheet>
<PQProviderSearch>classpath:/CustomerServiceRD/spring-integration/stylesheets/PQProviderSearch.xsl</PQProviderSearch>
</stylesheet>
<stylesheet>
<PQProviderSearchCount>classpath:/CustomerServiceRD/spring-integration/stylesheets/PQProviderSearchCount.xsl</PQProviderSearchCount>
</stylesheet>
<resultSet>
<legacySystem>system</legacySystem>
</resultSet>
<resultSet>
<rootNode>results</rootNode>
</resultSet>
<responseXml>
<soapTemplate>CustomerServiceRD/JobDesigner-responseTemplate.xml</soapTemplate>
</responseXml>
<responseXml>
<xmlBodyTag>//PQ</xmlBodyTag>
</responseXml>
<http>
<header>
<ressponseXml>
<contentType>
<value>CustomerServiceRD/JobDesigner-responseTemplate.xml</value>
</contentType>
</ressponseXml>
</header>
</http>
<http>
<header>
<contentType>
<value>CustomerServiceRD/JobDesigner-responseTemplate.xml</value>
</contentType>
</header>
</http>
<error>
<Fault>Fault</Fault>
</error>
<error>
<errorCode>1111</errorCode>
</error>
<headerNames>
<hostAddress>hostAddress</hostAddress>
</headerNames>
<headerNames>
<hostPort>hostPort</hostPort>
</headerNames>
<error>
<Fault>faultcode</Fault>
</error>
<error>
<faultstring>faultstring</faultstring>
</error>
<error>
<faultactor>faultactor</faultactor>
</error>
<error>
<detail>detail</detail>
</error>
<label>
<externalSystem>ExternalSystem</externalSystem>
</label>
</customerservice>
</config>
现在,我试图在spring集成配置文件中读取上述值,如下所示:
<beans
<import resource="spring-integration/Jobs/*.xml"/>
<!-- map of namespace prefix to URI -->
<util:map id="xmlMessageNamespace">
<entry key="SOAP" value="http://schemas.xmlsoap.org/soap/envelope/" />
</util:map>
<int:channel id="jobDesignerInputChannel" />
<int:channel id="cs-exceptionHandlingChannel" />
<bean id="msgHandler" class="com.dsths.cs.awd.jobs.PQMessageHandler" />
<!-- TODO: Following lines are commented out as part of POC.-->
<!--<bean id="xmlAggregator" class="com.dsths.cs.awd.jobs.XmlAggregator" />
<bean id="httpOutboundGatewayHandler" class="com.dsths.cs.awd.jobs.HttpOutboundGatewayHandler" />
<!--<bean id="xmlFilter" class="com.dsths.cs.awd.jobs.XmlFilter" />-->
<int:chain input-channel="jobDesignerInputChannel" >
<int-xml:xpath-header-enricher default-overwrite="true" should-skip-nulls="true" >
<int-xml:header name="${customerservice.headerNames.legacySystem}" xpath-expression="//LegacySystem" evaluation-type="STRING_RESULT" overwrite="true" />
</int-xml:xpath-header-enricher>
<!-- Some of the AWD jobs contain Business Area info under <code> tag, we should not keep that business area info in the
header since it is not required.This will help us in identifying AWD and Non-AWD jobs-->
<int:header-enricher>
<int:header name="${customerservice.headerNames.businessArea}" expression="#xpath(payload, '//businessArea/Code', 'boolean') ? null : #xpath(payload, '//businessArea')"/>
</int:header-enricher>
<int:router expression="${customerservice.routing.jobChannel}"/>
</int:chain>
<int:chain input-channel="cs-exceptionHandlingChannel">
<!-- Service Activator to handle the errors -->
<int:service-activator ref="msgHandler" method="handleError" />
<!-- Router to routing the error messages to appropriate job channel for xsl transormation -->
<int:router expression="${customerservice.routing.jobErrorChannel}"/>
</int:chain>
</beans>
但是,不幸的是,当我尝试从xml文件中读取属性时,我收到以下异常:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.handler.MessageHandlerChain#3': Cannot create inner bean 'org.springframework.integration.handler.MessageHandlerChain#3$child#2.handler' of type [org.springframework.integration.config.RouterFactoryBean] while setting bean property 'handlers' with key [2]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.handler.MessageHandlerChain#3$child#2.handler': Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'expressionString' threw exception; nested exception is org.springframework.expression.spel.SpelParseException: EL1041E:(pos 1): After parsing a valid expression, there is still more data in the expression: 'lcurly({)'
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:281)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:120)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:353)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:153)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1360)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:103)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:1)
at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:124)
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:148)
... 24 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.handler.MessageHandlerChain#3$child#2.handler': Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'expressionString' threw exception; nested exception is org.springframework.expression.spel.SpelParseException: EL1041E:(pos 1): After parsing a valid expression, there is still more data in the expression: 'lcurly({)'
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1396)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:270)
... 42 more
Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'expressionString' threw exception; nested exception is org.springframework.expression.spel.SpelParseException: EL1041E:(pos 1): After parsing a valid expression, there is still more data in the expression: 'lcurly({)'
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:102)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1393)
... 46 more
任何人都知道我做错了什么? 如果我的问题不明确,请告诉我。
答案 0 :(得分:1)
根据StackTrace,你的问题在这里:
<int:router expression="${customerservice.routing.jobChannel}"/>
在使用如此困难的配置之前,您应确保customerservice
确实返回所有需要的选项。
如果您已经从Java透视图中看到该对象的外观,而不是XML背景
,那将会很棒