Skip to main content

Command Palette

Search for a command to run...

XML based bean configuration in spring framework

Published
1 min read
S

I love learning about technology and sharing that with others

  • spring bean is an object which is created by spring container instantiates, assembles and manages

  • Application context manages the beans

  • several ways to configure beans in spring framework, java based, annotation based and xml based in my project they are doing xml based bean configuration

Example of XML based bean configuration

Finally, let's take a look at XML-based configuration. This is the traditional way of configuring beans in Spring.

Obviously, in this approach, we do all bean mappings in an XML configuration file.

So let's create an XML configuration file, account-bean-config.xml, and define beans for our AccountService class:


<?xml version="1.0" encoding="UTF-8"?>
<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.xsd">

  <bean id="accountService" class="com.baeldung.applicationcontext.AccountService">
    <constructor-arg name="accountRepository" ref="accountRepository" />
  </bean>

  <bean id="accountRepository" class="com.baeldung.applicationcontext.AccountRepository" />
</beans>

More from this blog

H

hashcodehub

271 posts

Consistent, Passionate and Organized :)