Google News
logo
Java Springs - Interview Questions
How is the configuration meta data provided to the spring container?
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="FreeTimeLearning" class="org.freetimelearn.firstSpring.FreeTimeLearning">
  <property name="name" value="freetimelearn"></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.

* @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.
Advertisement