Using Spring in a Custom ESB Service: Best place to declare

Posted by nweddle on 17-Jan-2008 09:02

I am planning to use Spring JDBC in one of my custom services, and I am wondering where the best place to put the ApplicationContext initialization is.

Here's the snippet:

ApplicationContext ctx = new ClassPathXmlApplicationContext("blah.xml");

No matter how many instances of the Service are created, I only want this line of code to run once. So... I suppose this should go into the init() method.

What do you all think?

Thanks,

Nathan

All Replies

Posted by tsteinbo on 05-Feb-2008 03:37

The ESB containers up to version 7.5.1 all instances in the same esb container share the same classloader. So if you initialize the context in your init method all other services in the same container will see the context. Thus, you should make sure you initialize only once if using many services using spring.

Starting from Sonic 7.6 onwards we will change the class loading and you have a class loader by service instance and service type and can also turn on self first class loading (as opposed to parent first, which is the default in the JVM). Using this you can isolate your spring contexts to a single service (type).

Hope this helps

Thomas

Posted by nweddle on 05-Feb-2008 11:02

Thomas,

That was very helpful, thanks for the information!

Nathan

This thread is closed