【问题标题】:Spring CamelContext Could not resolve placeholderSpring CamelContext 无法解析占位符
【发布时间】:2013-11-12 14:07:48
【问题描述】:

在我的应用程序中,我想用 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:初始化 Spring 根 WebApplicationContext lis 07, 2013 下午 3:57:44 org.apache.catalina.core.StandardContext listenerStart 严重:向侦听器发送上下文初始化事件的异常 类的实例 org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanDefinitionStoreException: 中定义的名称为“myEndpoint”的无效 bean 定义 null:无法解析占位符“header.name” 字符串值: "http4:...myUrl.../${header.name}/{{someData}}/${header.myId}"

我的临时解决方案:我将 header.nameheader.myId 添加到 application.properties(someData 所在的位置)并且它再次工作但我知道不应该这样做。 知道如何在不将这些值写入属性的情况下修复它吗?

【问题讨论】:

    标签: java spring apache-camel


    【解决方案1】:

    这是 Spring 框架中的一个限制。我们在 Apache Camel 网站上有一个常见问题解答,其中解释了这一点以及您可以做什么:http://camel.apache.org/how-do-i-use-spring-property-placeholder-with-camel-xml.html

    【讨论】:

    • 我按照您发送的网站上所说的做了一切,但仍然无法正常工作。我仍然不能强迫它不要求${header.name}
    • 您不能在 http4 端点中使用简单的语言。如果您想要动态 URI,请参阅此常见问题解答:camel.apache.org/how-do-i-use-dynamic-uri-in-to.html
    • @ClausIbsen 的 url 似乎没有无效/删除。这对于在互联网上找到的很多 url 都是一样的。
    猜你喜欢
    • 1970-01-01
    • 2016-07-24
    • 2018-02-20
    • 2017-05-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-12
    • 2020-10-05
    • 2017-08-17
    相关资源
    最近更新 更多