Spring - Configuration Metadata

[Updated: Aug 6, 2016, Created: Dec 2, 2015]

Spring configuration metadata is to tell Spring container how to initiate, configure, wire and assemble the application specific objects. Since it'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. Injection Points : The places where dependencies have to be injected. The Injection Points typically are fields/setters/constructors in a bean class. Spring framework populates/inserts the injection points with the required instances. That happens during the bean loading time.
  2. Service Providers : The concrete implementation of the services, whose instances are meant to be injected at injection Points. These classes themselves are registered as spring beans and can have injection points themselves.
  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 tutorial we are going to explore Java-based configurations in details.

See Also