拥有将 apache-activemq 服务器作为 spring bean 和几个 apache-camel 路由运行的 spring 应用程序(实际上是 grails 应用程序)。应用程序使用 hibernate 来处理数据库。问题很简单。 Activemq+Camel 启动之前
grails 将特殊方法注入(inject)到 hibernate 域对象中(实际上是保存/更新方法等)。因此,如果 activemq 在启动时已经有一些数据,camel 就会开始处理消息,而无需注入(inject) grails DAO 方法。此操作失败,并显示 grails.lang.MissingMethodException
。在 Grails 将特殊方法注入(inject)域对象之前,必须延迟 activemq/camel 启动。
最佳答案
如果所有这些都定义为spring bean,则可以使用
<bean id="activeMqBean" depends-on="anotherBean" />
这将确保 anotherBean
在 activeMqBean
之前初始化
关于spring - 如何延迟 spring beans 启动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3460344/