1. Introduction

Before Spring 3.0, XML was the only way to define and configure beans. Spring 3.0 introduced JavaConfig, allowing us to configure beans using Java classes. However, XML configuration files are still used today.

In this tutorial, we’ll discuss how to integrate XML configurations into Spring Boot.

2. The _@ImportResource _Annotation

The @ImportResource annotation allows us to import one or more resources containing bean definitions.

Let’s say we have a beans.xml file with the definition of a bean:

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xmlns:context="http://www.springframework.org/schema/context"    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">        <bean class="com.baeldung.springbootxml.Pojo">        <property name="field" value="sample-value"></property>    </bean></beans>

#spring #spring boot #xml

XML Defined Beans in Spring Boot
2.30 GEEK