java - Spring CamelContext 无法解析占位符

标签 java spring apache-camel

在我的应用程序中,我想使用 application.properties 中的 someData 填充端点 url,并彻底填充 header.nameheader.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.nameheader.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/

相关文章:

java - 在构建时,sun.audio无法正常工作

java.lang.IllegalArgumentException "Can not set DAO field"与 Spring 4 & Hibernate 4

json - 如何解决由Many TO Many hibernate双向映射引起的json序列化器中的循环引用?

java - Camel : CamelFailureEndpoint not set when sending exchange to DeadLetterChannel

apache-camel - 当处理失败并且异常由错误处理程序处理时,如何阻止camel删除FTP文件

rest - 从 Apache Camel route 的分页 API 读取

java - 在 HTTP Servlet 中使用连接池关闭连接的位置

java - Struts2.5.12 - 使用 ActionSupport 中的 getText 方法时的 NPE

Java面向对象编程: Building Object Trees/Object Families

java - 如何使用Spring Boot Web应用程序将对象放入AWS S3存储桶