views:

167

answers:

2

I have an abstract class, Foo, that has a non-abstract method called Bar. I have a class Baz that extends Foo and has its own unique constructor. By default, when Spring instantiates the Baz class upon startup, it will call the Baz constructor before passing values into parent class' method, Bar.

Is there a way to override this behavior so Bar will be called before Baz's constructor? Or, if I need to extend Spring's default behavior somehow, what would be the best way to go about doing this?

+2  A: 

It sounds to me like what you're describing is the way Java is designed to work. Objects have to be fully constructed (through constructors) before you can call any methods on that instance.

My spring code rarely use the constructors for much, since they're not much good. I have started using a few methods with the @PostConstruct annotation, which may suit your needs better.

krosenvold
+2  A: 

You might consider replacing the logic in the constructor with an afterPropertiesSet method. See the InitializingBean interface.

nsayer