Skip to main content

Spring Framework | XML vs Java Configuration

Spring Framework | XML vs Java Configuration


Before you start any Spring Framework project, you should consider using Spring Boot to simplify configuration.

https://start.spring.io is the place to start. Many IDEs also integrate with start.spring.io.

If you have legacy applications or otherwise like to torture yourself play with xml configuration then here is an example setup.

  1. Use the Spring BOM (Bill of Materials) using a dependency tool like Maven or Gradle to manage versions of various dependencies.
  2. Add your xml configuration file in the classpath (depends on whether you are building Web or regular Java jar application).
  3. Example class Greeting.java
class Greeting {
public String greeting(String name) {
return String.format("Hello %s", name);
}
}
 
XML configuration;

<?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-4.3.xsd">

<bean id="greeting" class="com.efeyopixel.Greeting">
<property name="name" value="spring fan!"></property>
</bean>

</beans>

Comments

Popular posts from this blog

Spring Boot Tips - What's the difference between @Component, @Service @Controller and @Repository

            Spring Boot Tips - What's the difference between @Component, @Service @Controller and @Repository

Use KeePass And Putty To SSH To Servers (Without Typing Passwords)

Use KeePass and Putty To SSH To Servers (No Password)

Interesting finds April 2022

 Interesting Finds for April 2022 A list of new(ish) command line tools (jvns.ca) Podman Desktop Companion (iongion.github.io) Analyzing iMessage with SQL | by Arctype | Mar, 2022 | Database Dive