Java versus XML configuration

With the advent of annotations in Java 5, there is widespread use of Java configuration for Spring based applications. What is the right choice to make if you have to choose between a Java-based configuration as opposed to an XML-based configuration?

Spring provides equally good support for Java and XML-based configuration. So, it's left to the programmer and their team to make the choice. Whichever choice is made, it is important to have consistency across teams and projects. Here are some things you might need to consider when making a choice:

  • Annotations lead to shorter and simpler bean definitions.
  • Annotations are closer to the code they are applicable on than the XML-based configuration.
  • Classes using annotations ...

Get Mastering Spring 5.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.