【问题标题】:How to get default apache camel context id or create new one如何获取默认的 apache camel 上下文 id 或创建新的
【发布时间】:2015-12-30 13:07:25
【问题描述】:

我对基于 apache camel 的应用程序有疑问。我的模块很少。在他们每个人中,我都有在 xml 文件中定义的骆驼路线,如下所示:

<routes xmlns="http://camel.apache.org/schema/spring">
       <route id="..." errorHandlerRef="myErrorHandler">
           ...
       </route>
       other routes...
</routes>

应用程序运行良好。但是当我的应用程序关闭时,我收到了警告:

org.apache.camel.RuntimeCamelException: org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'myErrorHandler': Singleton bean creation not allowed while the singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)

可能我收到此警告是因为 spring bean(在本例中为“myErrorHandler”)在骆驼上下文停止之前关闭。我在 apache camel 论坛上关注了一些类似的问题,人们建议设置取决于我在骆驼中使用的 bean 上的参数('myErrorHandler' bean),如下所示:

http://camel.465427.n5.nabble.com/quot-Singleton-bean-creation-not-allowed-while-the-singletons-of-this-factory-are-in-destruction-quon-td5713684.html

http://camel.465427.n5.nabble.com/Spring-destroys-camelTemplate-before-CamelContext-td5464452.html

但在我的情况下,我的 xml 中没有 camelContext 元素(如我所示,我只有 'routes' 元素),因此很难在我的 bean 中设置依赖于骆驼上下文 id。

任何想法如何解决这个问题?也许我可以在其他地方设置全局camelContext id并在我的bean定义中使用它?提前感谢您的帮助。

【问题讨论】:

  • 您的 xml 是其他一些常见 xml 的一部分?路线总是在骆驼上下文中定义的。您的应用程序肯定会有至少一个骆驼上下文。

标签: java spring apache error-handling javabeans


【解决方案1】:

只能在 之外定义路由,您可以在从 Camel 2.3 开始的新 标签中定义路由。
引用自:http://camel.apache.org/configuring-camel.html

您仍然需要 camelContext 来配置您的路线。所以我的猜测是你的路由 xml 被导入到一些常见的 xml 中,这些 xml 将具有 comeContext。 只需搜索并使用它。

【讨论】:

    【解决方案2】:

    我有几个模块可以导入到主模块。我正在使用 spring boot maven 插件来启动我的应用程序。 每个模块都有配置类,它使用自己的 @CamelConfiguration 注释导入我的骆驼文件(我之前展示过),其工作原理如下:

    @CamelConfiguration("path to file which contains route definition")
    public class MyConfiguration {
    }
    

    @CamelConfiguration 是其他人创建的注解,但它的目的是从特定的本地化加载路由。 主应用程序开始使用 SpringBoot 如下:

    SpringApplication.run
    

    并且启动骆驼的类有注解@SpringBootApplication。所以,我的 xml 文件中仍然没有“camelContext”元素。

    我做了一些不同的事情。在“myErrorHandler”bean 类中,我自动装配了 CamelContext(我可以访问此类的对象)。我希望如果我今年春天这样做不会破坏我的豆子,而骆驼上下文存在(应该作为依赖项工作)但它不起作用。还是一样的错误... 所以,最后,我不确定依赖会解决我的问题。也许我应该尝试不同的解决方案?

    编辑:我正在使用带有 spring boot 的 apache camel,如下所示: http://camel.apache.org/spring-boot.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多