diff --git a/parent-boot-performance/README.md b/parent-boot-performance/README.md new file mode 100644 index 0000000000..fce9e101da --- /dev/null +++ b/parent-boot-performance/README.md @@ -0,0 +1 @@ +This is a parent module for projects that want to take advantage of the latest Spring Boot improvements/features. \ No newline at end of file diff --git a/parent-boot-performance/pom.xml b/parent-boot-performance/pom.xml new file mode 100644 index 0000000000..b1c6854eae --- /dev/null +++ b/parent-boot-performance/pom.xml @@ -0,0 +1,91 @@ + + 4.0.0 + parent-boot-performance + 0.0.1-SNAPSHOT + parent-boot-performance + pom + Parent for all modules that want to take advantage of the latest Spring Boot improvements/features. Current version: 2.2 + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + + 3.1.0 + + 1.0.21.RELEASE + 2.2.0.M3 + + + + + + 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} + + + + + + + + diff --git a/spring-boot-performance/pom.xml b/spring-boot-performance/pom.xml new file mode 100644 index 0000000000..bbee7493cc --- /dev/null +++ b/spring-boot-performance/pom.xml @@ -0,0 +1,45 @@ + + 4.0.0 + spring-boot-performance + spring-boot-performance + war + This is a simple Spring Boot application taking advantage of the latest Spring Boot improvements/features. Current version: 2.2 + + + parent-boot-performance + com.baeldung + 0.0.1-SNAPSHOT + ../parent-boot-performance + + + + + com.baeldung.lazyinitialization.Application + + + + + org.springframework.boot + spring-boot-starter + + + + + spring-boot-performance + + + src/main/resources + true + + + + + + org.apache.maven.plugins + maven-war-plugin + + + + \ No newline at end of file diff --git a/spring-boot-performance/src/main/java/com/baeldung/lazyinitialization/Application.java b/spring-boot-performance/src/main/java/com/baeldung/lazyinitialization/Application.java new file mode 100644 index 0000000000..195b260399 --- /dev/null +++ b/spring-boot-performance/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-performance/src/main/java/com/baeldung/lazyinitialization/services/Writer.java b/spring-boot-performance/src/main/java/com/baeldung/lazyinitialization/services/Writer.java new file mode 100644 index 0000000000..7c67fb7ea4 --- /dev/null +++ b/spring-boot-performance/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-performance/src/main/resources/application.yml b/spring-boot-performance/src/main/resources/application.yml new file mode 100644 index 0000000000..25f03eed56 --- /dev/null +++ b/spring-boot-performance/src/main/resources/application.yml @@ -0,0 +1,3 @@ +spring: + main: + lazy-initialization: true \ No newline at end of file