|
Answer» There are 3 ways of providing the configuration metadata. They are as follows: - XML-Based configuration: The bean configurations and their dependencies are specified in XML configuration files. This starts with a bean tag as shown below:
<bean id="interviewBitBean" class="org.intervuewBit.firstSpring.InterviewBitBean"> <property name="name" value="InterviewBit"></property> </bean>- Annotation-Based configuration: Instead of the XML approach, the beans can be configured into the component class itself by using annotations on the RELEVANT class, method, or field declaration.
- Annotation wiring is not active in the SPRING container by default. This has to be enabled in the Spring XML configuration file as shown below
<beans><context:annotation-config/><!-- bean definitions go here --></beans>- Java-based configuration: Spring FRAMEWORK introduced key features as part of new Java configuration support. This makes USE of the @Configuration annotated classes and @Bean annotated methods. Note that:
- @Bean annotation has the same role as the <bean/> element.
- Classes annotated with @Configuration ALLOW to define inter-bean dependencies by simply calling other @Bean methods in the same class.
|