Spring Bean XML File

    0 Votes

In his article, we will have detailed look into the Spring bean XML file, bean Tag and Property Tag.

spring bean xml

Prolog
<?xml version="1.0" encoding="UTF-8"?>
We call it XML prolog; it is the first line of Xml which tells about xml version.
Beans Tag
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
Here we mention the XSD file for configuration XML. XSD stands for XML Schema Definition. It is a World Wide Web Consortium (W3C) recommendation that specifies how to formally describe the elements in an Extensible Markup Language (XML) document. In simple words, it says about the possible tags and it's attribute, which we can use in this configuration file.

schemLocation says where to found that XSD on Internet,

Bean Tag

<bean id="helloWorld" class="com.example.hello.HelloWorld">

Bean tag has two important attributes, id and class. The Id is the identifier of the bean, you can think it as the primary key of a table, or SSN of an American citizen. Class attribute provides fully qualified class name. Internally, Spring container load this bean using java reflection. Make sure that you provide an exact class name and unique id for a bean.

Property Tag

<property name="greet" value="Hello World! Welcome to Spring"/>

In each bean tag we define properties which are same as java attributes. If an Employee class have two properties say the name, address so we have to define two property tags under Employee bean and name of the property should match with java property. In Java bean, please provide a setter for that property since Spring injects value attribute using that setter.

Popular Videos

How to speak to people

How to speak so that people want to listen.

Got a tip or Question?
Let us know

Related Articles

Spring Framework - Overview
Spring Architecture
Step by step guide for Spring configuration
Building First Spring application
Spring Container
Spring Bean - Learn with an Example
Spring Bean Scope
Spring Bean Life Cycle
Spring Bean Post Processor
Spring Inner Bean
Spring Autowiring
Spring Autowiring Types
Spring Qualifier with Autowiring
Spring Collection Injection
Spring Inheritance
Spring Event Handling
Dependency Injection
Spring AOP
Spring AOP Example