calling method after properties are set in Spring

Hi,

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 {

@Autowired
private MyDao dao;

@Autowired
private MyOtherDao otherDao;

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

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s