在我的应用程序中,我想使用 application.properties 中的 someData 填充端点 url,并彻底填充 header.name 和 header.myId在使用 myEndpoint 之前。
my_bean.xml:
<camel:camelContext id="camel" xmlns="http://camel.apache.org/schema/spring" >
<propertyPlaceholder id="properties" location="ref:myProps"/>
<endpoint id="myEndpoint" uri="...myUrl.../${header.name}/{{someData}}/${header.myId}"/>
<route id="myRoute" trace="true">
...
</route>
</camel:camelContext>
它工作得很好,我创建了测试,一切都很棒,我将 my_bean.xml 添加到 web.xml 中,以便使用我在另一个类中使用此端点的类。将其添加到 web.xml 后出现错误:
INFO: Initializing Spring root WebApplicationContext lis 07, 2013 3:57:44 PM org.apache.catalina.core.StandardContext listenerStart SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'myEndpoint' defined in null: Could not resolve placeholder 'header.name' in string value: "http4:...myUrl.../${header.name}/{{someData}}/${header.myId}"
我的临时解决方案:我将 header.name 和 header.myId 添加到 application.properties (其中 someData 所在),它再次工作但我知道不应该这样做。 知道如何在不将这些值写入属性的情况下修复它吗?
最佳答案
这是 Spring 框架的一个限制。我们在 Apache Camel 网站上提供了常见问题解答,其中解释了这一点以及您可以执行的操作:http://camel.apache.org/how-do-i-use-spring-property-placeholder-with-camel-xml.html
关于java - Spring CamelContext 无法解析占位符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19931353/