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 集合/集合问题

java - 从 java 中的自定义查询检索结果集

apache-camel - 为什么ActiveMQ 5.14.x无法启动嵌入camel-jms组件2.18.3

java - 使用camel流式传输文件

web-services - Apache Camel 聚合多个REST服务响应

java - 可以将数据类型保存到变量吗? (数据类型 = 整数)?

java - android中文件的访问路径作为字符串

java - 如何使用 Spring @Configuration 而不是 XML 配置检索 JNDI

java - 包括 Spring Jaxb2Marshaller 的 DOCTYPE

spring - 不能很好地理解spring-mvc的 `@Autowired HttpServletRequest`