我对基于 apache camel 的应用程序有疑问。我的模块很少。在他们每个人中,我都有在 xml 文件中定义的 Camel 路线,如下所示:
<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')在 Camel 上下文停止之前关闭。我在 apache camel 论坛上关注了一些类似的问题,人们建议设置取决于我在 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 元素(如我所示,我只有“路由”元素),因此很难在我的 bean 中设置依赖于 Camel 上下文 id。
任何想法如何解决这个问题?也许我可以在其他地方设置全局camelContext id并在我的bean定义中使用它?在此先感谢您的帮助。
最佳答案
只能在从 Camel 2.3 开始的新
引用自:http://camel.apache.org/configuring-camel.html
您仍然需要 camelContext 来配置您的路线。所以我的猜测是你的路由 xml 被导入到一些常见的 xml 中,这些 xml 将具有 comeContext。
只需搜索并使用它。
关于java - 如何获取默认的 apache camel 上下文 id 或创建新的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34530175/