0

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 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

yeah you are right Avi. But for standalone java project with spring means is there any way to handle it???
@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.
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.