How configuration metadata is provided to the Spring container?

Configuration metadata can be provided to Spring container in following ways:

  1. XML-Based configuration
  2. Annotation-Based configuration
  3. Java-based configuration

XML-Based configuration: In Spring Framework, the dependencies and the services needed by beans are specified in configuration files which are in XML format. These configuration files usually contain a lot of bean definitions and application specific configuration options. They generally start with a bean tag.

Example:-

Annotation-Based configuration: Instead of using XML to describe a bean wiring, you can configure the bean into the component class itself by using annotations on the relevant class, method, or field declaration. By default, annotation wiring is not turned on in the Spring container. So, you need to enable it in your Spring configuration file before using it.

Example:-

Java-based configuration: The key features in Spring Framework’s new Java-configuration support are @Configuration annotated classes and @Bean annotated methods.

@Bean annotation plays the same role as the <bean/> element.

@Configuration classes allows to define inter-bean dependencies by simply calling other @Bean methods in the same class.

Example:-