This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I've used XML configuration and Annotation, but I found that Spring Annotation is a choice to go due to it simple and straight forward. No more wiring and tons of xml configuration, I found that Annotation is far more efficient and maintenance free compared to xml.
The choice is yours...
"Your life is in your hands, to make of it what you choose."
In addition to that thread from earlier this year, let me make it clear that choosing to use annotations for dependency injection does not necessarily mean that you'll be placing Spring-specific annotations in your code.
One basic thing you can do is use javax.inject annotations (@Named and @Inject) instead of Spring annotations (@Component and @Autowired). These annotations are roughly equivalent and Spring supports them. So you won't be using Spring-specific annotations, you'll be using standard "passed through the JCP" annotations.
Also, with regard to the @Component annotation, you have another option: Create your own annotation, with runtime retention and annotate it with @Component. Now your custom annotation will work in place of @Component. So the only place you're using @Component is in the definition of your custom annotation--you'll use your annotation everywhere else.
Finally, you might consider using Spring's Java-based configuration. Yes, you'll be using Spring-specific annotations, but those annotations will be confined to configuration classes (which are like Spring's XML, but expressed in Java). Your application code won't need Spring annotations.
That said...and as I said before...use XML if you like, use annotations if you like, or use both (applying each where it makes the most sense). The nice thing is that Spring gives you the choice.
Thanks for expert opinions. Is it possible to mix and match. Use xml and annotations in combintaion ? Also if I am using Spring annotations in a class and use the class in non -spring environment with no spring jar files in classpath, when the class gets loaded will it throw ClassNotFoundException as annotaions are not in classpath.