tags:

views:

68

answers:

3

Having spring application (actually grails app) that runs apache-activemq server as spring bean and couple of apache-camel routes. Application use hibernate to work with database. The problem is simple. Activemq+Camel starts up BEFORE grails injects special methods into hibernate domain objects (actually save/update methods etc). So, if activemq already has some data on startup - camel starts processing messages w/o having grails DAO methods injected. This fails with grails.lang.MissingMethodException. Must delay activemq/camel startup before Grails injects special methods into domain objects.

A: 

If all these are defined as spring bean, you can use

<bean id="activeMqBean depends-on="anotherBean" />

This will make sure anotherBean is initialized before activeMqBean

Bozho
Thanks Bonzo, but I know `depends-on` statement. Unfortunately it won't work as Grails initialization is on some different layer then Spring. So there's just no bean that activemq should depend on.
archer
+3  A: 

can you move MQ managment into a plugin? It would increase modularity and if you declare in plugin-descriptor

def loadAfter = ['hibernate']

you should have the desired behavior. Works for JBPM plugin

Sammyrulez
Well, honestly I would NOT create/maintain separate plugin just to startup AMQ after hibernate is loaded. I'm assured that there's better way.
archer
well in grails plugins are component. I have developed several plugin for apps just because I thought they would have been better modularized. Plugins are also a useful way to integrate legacy data or system. You maintain them as you maintain the app. You don't have to release them into the wild.
Sammyrulez
I've got it ;) But in any case - I would NOT move single activemq.xml initialization file from main app into another `component` with complete grails plugin project structure, post it to svn and maintain another bunch of sources just to delay AMQ initialization.There's simpler way. AMQ bean support `start` property which indicates should it be autostarted or not. Will use it as for now.
archer
A: 

I am not sure in your case but lazy loading may also help e.g.

<bean id="lazybean" class="com.xxx.YourBean" lazy-init="true">

A lazily-initialized bean indicates to the IoC container to create bean instance when it is first requested. This can help you delay the loading of beans you want.

Gopi
This won't work also, as my DAO bean is for sure requested BEFORE hibernate is loaded.
archer