views:

354

answers:

2

Are there any hooks into the Spring ApplicationContext loading process?

I want to run a piece of code just before the application context loads (before any beans/properties/aspects/etc... are instantiated).

thanks in advance

+2  A: 

Maybe BeanFactoryPostProcessors will suite your needs? They are run after the whole XML configuration files are read, but before any (other) beans are instantiated.

Grzegorz Oledzki
great, that's what i was after, thanks very much
mlo55
+1  A: 

You can also use the ApplicationListener to receive notification of events like ContextClosedEvent, ContextStartedEvent or ContextStoppedEvent.

More information in the IoC Container chapter.

Vladimir
I don't think `ApplicationListeners` get notified *before* the context starts up, there doesn't seem to be an event for that.
skaffman
from the ContextRefreshedEvent JavaDoc: "Event raised when an ApplicationContext gets initialized or refreshed." I'll ckeck tonight if the event is sent *before* the initialization or just after.
Vladimir