calling method after properties are set in Spring


if you want to call a method which you want to be run after all the injections are done just do the following:

1. Make your class implement org.springframework.beans.factory.InitializingBean
2. override afterPropertiesSet method

and that is it. Sample code will be like:

public class MyBean implements InitializingBean {

private MyDao dao;

private MyOtherDao otherDao;

public void afterPropertiesSet() throws Exception {
System.out.println("this will be called after all the setters are done.");

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s