tags:

views:

34

answers:

2

This is crazy... been using Spring for a while but can't find something like the "init-method" that gets invoked AFTER all the dependencies have been injected.

I saw the BeanPostProcessor thingie but I am looking for something lightweight and non-intrusive that doesn't couple my beans to Spring. Like the init-method!

+1  A: 

You need to implement InitializingBean interface and override the afterPropertiesSet method.

Teja Kantamneni
But then I have to include Spring on the build path when building my pojos... there's no XML-only way?
Kevin Pauli
+1 This was exactly what I was looking for.
stacker
+1  A: 

With Spring 2.5 and above, if an object requires invocation of a callback method upon initialization, that method can be annotated with the @PostConstruct annotation.

For example:

public class MyClass{

   @PostConstruct
   public void myMethod() {
     ...
   }
   ...
} 

This is less intrusive than the BeanPostProcessor approach.

StudiousJoseph
But then I have to include Spring on the build path when building my pojos... there's no XML-only way?
Kevin Pauli
Nevermind, I see that @PostConstruct is in the javax.annotation package. Thanks!
Kevin Pauli