Now based on this link http://www.mkyong.com/spring/spring-postconstruct-and-predestroy-example/ i done but in that example they using xml files so please help me to do using spring annotation or other way thanks in advance...
1 Answer
It doesn't matter how you create your bean (XML, annotation, @Configuration class). As long
as you have the <context:annotation-config /> it should work.
If you use @Configuration class you should add this annotation as well to the base configuration class @EnableWebMvc
They even mention adding it in the tutorial you referred to.
3 Comments
Sujeeth Damodharan
yeah you are right Avi. But for standalone java project with spring means is there any way to handle it???
Avi
@SujeethDamodharan - You have to have an initial spring context in any case. Anyway, I edited my answer and added the right annotation to use when configuring with configuration class and not with XML. But still in a standalone app you need to programatically load the context somehow in order for the annotations to work.
Sujeeth Damodharan
Thanks a lot Avi. i found this AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext ( RootConfig.class ); to enable the annotation . In Root configuration i defined all required bean its working like a charm for standalone java app with Spring :) :) #Thanks