DEV Community

Cover image for Twitter, SMS Services: Spring Boot possible XML Configuration
Hamdamboy
Hamdamboy

Posted on

Twitter, SMS Services: Spring Boot possible XML Configuration

The system configuration is important building real project and interoperable dependency injection. This article we will quickly discuss how to develop a simple Spring boot 2 application using XML based Spring configuration. Indeed, Twitter, SMS, Email systems are proceeding in Java Spring implementation and using XML. Indeed, as usual open source in the github, just use it.

In this example, we don't use either Annotation-based configuration or Java-based configuration, we only use XML based configuration to create and configure beans.
Spring provides a @ImportResource annotation is used to load beans from an applicationContext.xml file into an Application Context.

@ImportResource({"classpath*:applicationContext.xml"})

we are creating a simple message processing spring boot application. Here we are sending a message using different services like SMSService, TwitterService, and EmailService. We will configure message service beans in applicationContext.xml file and we will load beans using @ImportResource annotation as (see more source explanation github). Figure -1. XML configuration in Spring Boot.

Alt Text
Figure-1. XML Configuration in Spring Boot

The applicationContext.xml File

There is simplify source code in applicationContext.xml file:
> * Source code

      <?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 id ="emailService"
      class="spring.configure.service.EmailService" />
      <bean id="sMSService"
      class="spring.configure.service.SmsService" />
      <bean id="twitterService"
      class="spring.configure.service.TwitterService" />
      <bean id="messageProcessor"
      class="spring.configure.service.MessageProcessorImpl">
      <property name="messageService" ref="twitterService"></property>
      </bean>
      </beans>

The essential point is you may update inside XML source code <bean id ="emailService". in your main folder address and work-space.

Top comments (0)