Question - How configuration metadata is provided to the Spring container?
Answer -
Configuration metadata can be provided to Spring container in following ways:
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. For 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. For example:
Java-based configuration: The key features in Spring Framework’s new Java-configuration support are @Configuration annotated classes and @Bean annotated methods.
1. @Bean annotation plays the same role as the element.
2.@Configuration classes allows to define inter-bean dependencies by simply calling other @Bean methods in the same class.
For example:
- @Configuration
- public class StudentConfig
- {
- @Bean
- public StudentBean myStudent()
- { return new StudentBean(); }
- }