×
☰ See All Chapters

Spring Configuration File

Spring bean configuration file contains spring bean configurations, dependent value configurations, and other miscellaneous configurations. Any name can be given to Spring Bean configuration file with .xml extension. <beans> tag is the root element., this encloses all the spring definitions.  <bean> tag defines spring bean i.e. a java class to be initialized and managed by spring core container. Every spring bean class must be configured in spring configuration file, and then only spring container recognizes that class. Every Spring Bean will be identified through its Bean id, which is a value given in id attribute of <bean>. Placing DOCTYPE statements or schema statements (namespace) at the top of the spring configuration file is mandatory. For each module in spring we have to use separate DOCTYPE statements or schema statements (namespace)

    1. DOCTYPE statements for dtd rules  

    2. Schema statements(namespace) for xsd rules  

We can use any one either DOCTYPE statements or schema statements (namespace). XML Schema-based configuration introduced in Spring 2.0. It is most used in spring apps.  

Spring Configuration File example

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "https://www.springframework.org/dtd/spring-beans.dtd">

<beans>

        <bean id="studentbean" class="com.java4coding.Student">

                <property name="name" value="Manu_Manjunatha"></property>

        </bean>

</beans>

 

Or

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="https://www.springframework.org/schema/beans"

        xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"

        xsi:schemaLocation="https://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">

 

        <bean id="studentbean" class="com.java4coding.Student">

                <property name="name" value="Manu_Manjunatha"></property>

        </bean>

</beans>

 


All Chapters
Author