views:

16

answers:

2

Does spring (spring mvc) have an event that gets fired once, on application startup, where I can hook in and load some objects?

+1  A: 

Can't you just use the normal initialization mechanisms of a singleton bean, e.g. @PostConstruct or InitializingBean? A singleton bean will only be created/initialized once at context startup.

Alternatively, you can implement the Lifecycle interface, which gets callbacks from Spring when the context itself start up or shuts down, rather than the bean itself.

skaffman
ah ok, that's perfect thanks for the suggestion.
Blankman
+1  A: 

If you are not going to refresh your application context, you can simply listen to

org.springframework.context.event.ContextRefreshedEvent

Adrian Shum