Close

Spring - Configuration Metadata

[Last Updated: May 2, 2021]

Spring configuration metadata needs to be created to tell Spring container how to initiate, configure, wire and assemble the application specific objects.

Since Spring's first release in 2002 to the latest release, spring has provided three ways of configurations:

  1. XML-based Configuration : All configurations are in one or multiple XML files. This is the most verbose way of configuration. Huge projects require tedious amount of XML which is difficult to manage.
  2. Annotation-based configuration : Spring 2.5 introduces annotation-based configuration. We still have to write XML files but just to indicate "component-scan" on the packages of annotated classes.
  3. Java-based configuration (JavaConfig): Starting with Spring 3.0, a pure-Java means of configuring container was provided. We don't need any XML with this method of configuration. JavaConfig provides a truly object-oriented mechanism for dependency injection, meaning we can take full advantage of reusability, inheritance and polymorphism in the configuration code. Application developer has complete control over instantiation and dependency injection here.

In these tutorials we will mainly focus only on JavaConfig. Learning only one method is good enough to understand key concepts and features of Spring container.

Regardless of what method we use, we mainly have to use configuration metadata at three places:

  1. Beans : The objects managed by Spring Container. They are are registered to the Spring container by the use of some metadata.
  2. Injection Points : The places where dependencies have to be injected. The Injection Points typically are fields/setters/constructors in a Spring bean class. Spring framework populates/inserts the injection points with the required instances of other beans. That happens during the bean loading time.
  3. The Configuration : This can be a Java class annotated with @Configuration or it can be XML if we are using old way of configuration. This is where we wire the injection points with dependencies.

What's next?

In next tutorials we are going to explore Java-based configurations in details.

See Also