From 333dad149fcaec6fe36f64d0375d4b00f9029828 Mon Sep 17 00:00:00 2001 From: marcodenisi Date: Thu, 18 Jun 2020 17:49:10 +0200 Subject: [PATCH] BAEL-4083 - sample spring boot app with xml config and properties --- spring-boot-modules/pom.xml | 1 + spring-boot-modules/spring-boot-xml/pom.xml | 32 +++++++++++++++++++ .../java/com/baeldung/springbootxml/Pojo.java | 17 ++++++++++ .../SpringBootXmlApplication.java | 25 +++++++++++++++ .../SpringBootXmlWithConfigApplication.java | 23 +++++++++++++ .../src/main/resources/application.properties | 1 + .../src/main/resources/beans.xml | 13 ++++++++ .../src/main/resources/beansconf.xml | 15 +++++++++ 8 files changed, 127 insertions(+) create mode 100644 spring-boot-modules/spring-boot-xml/pom.xml create mode 100644 spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/Pojo.java create mode 100644 spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/SpringBootXmlApplication.java create mode 100644 spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/SpringBootXmlWithConfigApplication.java create mode 100644 spring-boot-modules/spring-boot-xml/src/main/resources/application.properties create mode 100644 spring-boot-modules/spring-boot-xml/src/main/resources/beans.xml create mode 100644 spring-boot-modules/spring-boot-xml/src/main/resources/beansconf.xml diff --git a/spring-boot-modules/pom.xml b/spring-boot-modules/pom.xml index 7992c0ce12..8ef3d34056 100644 --- a/spring-boot-modules/pom.xml +++ b/spring-boot-modules/pom.xml @@ -57,6 +57,7 @@ spring-boot-springdoc spring-boot-testing spring-boot-vue + spring-boot-xml diff --git a/spring-boot-modules/spring-boot-xml/pom.xml b/spring-boot-modules/spring-boot-xml/pom.xml new file mode 100644 index 0000000000..dd575ff414 --- /dev/null +++ b/spring-boot-modules/spring-boot-xml/pom.xml @@ -0,0 +1,32 @@ + + + + parent-boot-2 + com.baeldung + 0.0.1-SNAPSHOT + ../../parent-boot-2 + + + 4.0.0 + + spring-boot-xml + + + + org.springframework.boot + spring-boot-starter + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/Pojo.java b/spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/Pojo.java new file mode 100644 index 0000000000..8c8b47ed40 --- /dev/null +++ b/spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/Pojo.java @@ -0,0 +1,17 @@ +package com.baeldung.springbootxml; + +public class Pojo { + + private String field; + + public Pojo() { + } + + public String getField() { + return field; + } + + public void setField(String field) { + this.field = field; + } +} diff --git a/spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/SpringBootXmlApplication.java b/spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/SpringBootXmlApplication.java new file mode 100644 index 0000000000..1a0350fd26 --- /dev/null +++ b/spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/SpringBootXmlApplication.java @@ -0,0 +1,25 @@ +package com.baeldung.springbootxml; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.ImportResource; + +@Configuration +@EnableAutoConfiguration +@ImportResource("classpath:beans.xml") +public class SpringBootXmlApplication implements CommandLineRunner { + + @Autowired private Pojo pojo; + + public static void main(String[] args) { + SpringApplication.run(SpringBootXmlApplication.class, args); + } + + public void run(String... args) { + System.out.println(pojo.getField()); + } + +} diff --git a/spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/SpringBootXmlWithConfigApplication.java b/spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/SpringBootXmlWithConfigApplication.java new file mode 100644 index 0000000000..7c36ac7905 --- /dev/null +++ b/spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/SpringBootXmlWithConfigApplication.java @@ -0,0 +1,23 @@ +package com.baeldung.springbootxml; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.ImportResource; + +@Configuration +@ImportResource("classpath:beansconf.xml") +public class SpringBootXmlWithConfigApplication implements CommandLineRunner { + + @Autowired private Pojo pojo; + + public static void main(String[] args) { + SpringApplication.run(SpringBootXmlWithConfigApplication.class, args); + } + + @Override + public void run(String... args) throws Exception { + System.out.println(pojo.getField()); + } +} diff --git a/spring-boot-modules/spring-boot-xml/src/main/resources/application.properties b/spring-boot-modules/spring-boot-xml/src/main/resources/application.properties new file mode 100644 index 0000000000..ab9de92c82 --- /dev/null +++ b/spring-boot-modules/spring-boot-xml/src/main/resources/application.properties @@ -0,0 +1 @@ +sample=string loaded from properties! \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-xml/src/main/resources/beans.xml b/spring-boot-modules/spring-boot-xml/src/main/resources/beans.xml new file mode 100644 index 0000000000..9dac0d9e65 --- /dev/null +++ b/spring-boot-modules/spring-boot-xml/src/main/resources/beans.xml @@ -0,0 +1,13 @@ + + + + + + + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-xml/src/main/resources/beansconf.xml b/spring-boot-modules/spring-boot-xml/src/main/resources/beansconf.xml new file mode 100644 index 0000000000..7f328370a8 --- /dev/null +++ b/spring-boot-modules/spring-boot-xml/src/main/resources/beansconf.xml @@ -0,0 +1,15 @@ + + + + + + + + + \ No newline at end of file