my MainPractise02.java file were main method is present , is as follows,
now the ouput on command prompt as follows,
my questions are,
why method postProcessBeforeInitialization() is called everytime whenever other beans declared in bean-cfg.xml are initialised ?,
why methods postProcessAfterInitialization() and destroy() were not called ?
1) You are using BeanFactory instead of your instance variable being ApplicationContext, probably why the post of the BeanPostProcessor doesn't get called.
2) a BeanPostProcessor will always receive every bean declared in your configuration because that is what BeanPostProcessors are about, they post process all your beans. Basically they get passed the entire Map of beans and loops through them all to see if they need to do something to that bean.
Rahul Shivsharan wrote:i didn't understood the first point,
Are you saying that as i'm using BeanFactory thats the reason postProcessesAfterinitialisation() and destroy() methods are not getting called ?
Can you explain me , please
The BeanFactory is the older way to use Spring, it used to be the Spring Container that was used. Then Spring introduced the ApplicationContext, which added new features including more steps into the Initialization Phase, which is what you are looking at. The BeanPostProcessor step was not part of the BeanFactory initialization lifecycle. But it is with ApplicationContext. ApplicationContext is a Bean Factory plus more.
The destroy method only gets called when you call close() on the ApplicationContext, and that method is only on the ConfigurableApplicationContext interface, so you would have to cast your ApplicationContext to that type, then call close().
Joined: Jun 17, 2009
I changed the code as you said but still it gives a nullpointer exception,
I did the changes in file MainPractise04.java ,
and the command prompt shows
Joined: Jun 17, 2009
i removed the try catch and did changes as you said,
my changed file MainPractise04.java,
but still it gives an exception as nullpointer
you can see, the bean Juggler is getting initialised the sop is printed,
so than why spring container is not able to invoke method perform() ?