From 238e75eec9e79dd09a269d6b921f76169247b3c0 Mon Sep 17 00:00:00 2001 From: Joel Juarez Date: Sun, 19 May 2019 22:03:12 +0200 Subject: [PATCH] added parent module for spring boot 2.2 added module for spring boot 2.2 added example for lazy initialization in spring boot 2.2 --- parent-boot-2-2/README.md | 2 + parent-boot-2-2/pom.xml | 91 +++++++++++++++++++ spring-boot-2-2/pom.xml | 45 +++++++++ .../lazyinitialization/Application.java | 32 +++++++ .../lazyinitialization/services/Writer.java | 16 ++++ .../src/main/resources/application.yml | 3 + 6 files changed, 189 insertions(+) create mode 100644 parent-boot-2-2/README.md create mode 100644 parent-boot-2-2/pom.xml create mode 100644 spring-boot-2-2/pom.xml create mode 100644 spring-boot-2-2/src/main/java/com/baeldung/lazyinitialization/Application.java create mode 100644 spring-boot-2-2/src/main/java/com/baeldung/lazyinitialization/services/Writer.java create mode 100644 spring-boot-2-2/src/main/resources/application.yml diff --git a/parent-boot-2-2/README.md b/parent-boot-2-2/README.md new file mode 100644 index 0000000000..d2bd6d660b --- /dev/null +++ b/parent-boot-2-2/README.md @@ -0,0 +1,2 @@ + +This is a parent module for all projects using Spring Boot 2.2. diff --git a/parent-boot-2-2/pom.xml b/parent-boot-2-2/pom.xml new file mode 100644 index 0000000000..59611c9044 --- /dev/null +++ b/parent-boot-2-2/pom.xml @@ -0,0 +1,91 @@ + + 4.0.0 + parent-boot-2-2 + 0.0.1-SNAPSHOT + parent-boot-2-2 + pom + Parent for all Spring Boot 2.2 modules + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + + + + io.rest-assured + rest-assured + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot.version} + + ${start-class} + + + + + + + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + + + + + thin-jar + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.springframework.boot.experimental + spring-boot-thin-layout + ${thin.version} + + + + + + + + + + 3.1.0 + + 1.0.21.RELEASE + 2.2.0.M3 + + diff --git a/spring-boot-2-2/pom.xml b/spring-boot-2-2/pom.xml new file mode 100644 index 0000000000..4390e29b60 --- /dev/null +++ b/spring-boot-2-2/pom.xml @@ -0,0 +1,45 @@ + + 4.0.0 + spring-boot-2-2 + spring-boot-2-2 + war + This is simple boot application for Spring boot 2.2 + + + parent-boot-2-2 + com.baeldung + 0.0.1-SNAPSHOT + ../parent-boot-2-2 + + + + + org.springframework.boot + spring-boot-starter + + + + + spring-boot-2-2 + + + src/main/resources + true + + + + + + org.apache.maven.plugins + maven-war-plugin + + + + + + + com.baeldung.lazyinitialization.Application + + \ No newline at end of file diff --git a/spring-boot-2-2/src/main/java/com/baeldung/lazyinitialization/Application.java b/spring-boot-2-2/src/main/java/com/baeldung/lazyinitialization/Application.java new file mode 100644 index 0000000000..195b260399 --- /dev/null +++ b/spring-boot-2-2/src/main/java/com/baeldung/lazyinitialization/Application.java @@ -0,0 +1,32 @@ +package com.baeldung.lazyinitialization; + +import com.baeldung.lazyinitialization.services.Writer; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; + +@SpringBootApplication +public class Application { + + @Bean("writer1") + public Writer getWriter1() { + return new Writer("Writer 1"); + } + + @Bean("writer2") + public Writer getWriter2() { + return new Writer("Writer 2"); + } + + public static void main(String[] args) { + ApplicationContext ctx = SpringApplication.run(Application.class, args); + System.out.println("Application context initialized!!!"); + + Writer writer1 = ctx.getBean("writer1", Writer.class); + writer1.write("First message"); + + Writer writer2 = ctx.getBean("writer2", Writer.class); + writer2.write("Second message"); + } +} diff --git a/spring-boot-2-2/src/main/java/com/baeldung/lazyinitialization/services/Writer.java b/spring-boot-2-2/src/main/java/com/baeldung/lazyinitialization/services/Writer.java new file mode 100644 index 0000000000..7c67fb7ea4 --- /dev/null +++ b/spring-boot-2-2/src/main/java/com/baeldung/lazyinitialization/services/Writer.java @@ -0,0 +1,16 @@ +package com.baeldung.lazyinitialization.services; + +public class Writer { + + private final String writerId; + + public Writer(String writerId) { + this.writerId = writerId; + System.out.println(writerId + " initialized!!!"); + } + + public void write(String message) { + System.out.println(writerId + ": " + message); + } + +} diff --git a/spring-boot-2-2/src/main/resources/application.yml b/spring-boot-2-2/src/main/resources/application.yml new file mode 100644 index 0000000000..25f03eed56 --- /dev/null +++ b/spring-boot-2-2/src/main/resources/application.yml @@ -0,0 +1,3 @@ +spring: + main: + lazy-initialization: true \ No newline at end of file