in Spring by
How is the configuration meta data provided to the spring container?

1 Answer

0 votes
by

There are 3 ways of providing the configuration meta data. They are as follows:

XML-Based configuration: The bean configurations and its 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 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 of the <bean/> element.

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

Related questions

0 votes
asked Apr 4, 2021 in Spring by Robindeniel
0 votes
asked Apr 4, 2021 in Spring by Robindeniel
0 votes
asked Apr 4, 2021 in Spring by Robindeniel
...