From 894608083c951b9206c5787e68b1053166ad66fe Mon Sep 17 00:00:00 2001 From: Andrus Adamchik Date: Sat, 31 Mar 2018 19:33:05 +0300 Subject: [PATCH] adding classic Spring --- README.md | 18 +++++--- pom.xml | 2 + spring/pom.xml | 43 +++++++++++++++++++ .../java/org/objectstyle/spring/Main.java | 28 ++++++++++++ 4 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 spring/pom.xml create mode 100644 spring/src/main/java/org/objectstyle/spring/Main.java diff --git a/README.md b/README.md index d34ed15..89a1cfb 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # DI Containers Comparision -Comparing a simple app written with Cayenne DI, Dagger 2, -Guice and SpringBoot. +Comparing a simple app varieties on different DI containers. ## IntelliJ IDEA Setup @@ -11,8 +10,13 @@ Processing". ## "Benchmark" ``` +# Warmup build $ mvn clean package +# Measure assembly time with "-o" to ensure loading dependencies over +# the network does not interfere... +$ mvn clean package -o + # Get the file sizes $ find . -name '*.jar' |xargs ls -l |grep -v original |grep -v common @@ -20,6 +24,7 @@ $ find . -name '*.jar' |xargs ls -l |grep -v original |grep -v common $ time java -jar ./cayennedi/target/cayennedi-1.0-SNAPSHOT.jar $ time java -jar ./dagger/target/dagger-1.0-SNAPSHOT.jar $ time java -jar ./guice/target/guice-1.0-SNAPSHOT.jar +$ time java -jar ./spring/target/spring-1.0-SNAPSHOT.jar $ time java -jar ./springboot/target/springboot-1.0-SNAPSHOT.jar ``` @@ -27,7 +32,8 @@ $ time java -jar ./springboot/target/springboot-1.0-SNAPSHOT.jar |DI|Compile/Package Time, ms|Jar with Dependencies, KB|Exec time, ms| |----|-----|-----|----| -|Dagger|1320|51|122| -|Cayenne DI|93|79|166| -|Guice|483|3440|353| -|Spring Boot|527|6993|1628| +|Dagger|1297|51|121| +|Cayenne DI|91|79|180| +|Guice|477|3440|358| +|Spring|468|3545|506| +|Spring Boot|441|6993|1549| diff --git a/pom.xml b/pom.xml index 8a4f210..edd84a7 100644 --- a/pom.xml +++ b/pom.xml @@ -17,6 +17,7 @@ 2.15 4.2.0 4.0.B2 + 5.0.3.RELEASE 2.0.0.RELEASE @@ -25,6 +26,7 @@ dagger guice cayennedi + spring springboot diff --git a/spring/pom.xml b/spring/pom.xml new file mode 100644 index 0000000..c515e67 --- /dev/null +++ b/spring/pom.xml @@ -0,0 +1,43 @@ + + + 4.0.0 + + + org.objectstyle.di + di-comparison + 1.0-SNAPSHOT + + + spring + 1.0-SNAPSHOT + + jar + + + org.objectstyle.spring.Main + + + + + org.objectstyle.di + common + ${project.version} + + + org.springframework + spring-context + ${spring.version} + + + + + + + maven-shade-plugin + + + + + \ No newline at end of file diff --git a/spring/src/main/java/org/objectstyle/spring/Main.java b/spring/src/main/java/org/objectstyle/spring/Main.java new file mode 100644 index 0000000..3c7cb25 --- /dev/null +++ b/spring/src/main/java/org/objectstyle/spring/Main.java @@ -0,0 +1,28 @@ +package org.objectstyle.spring; + +import org.objectstyle.di.service.Service; +import org.objectstyle.di.service.ServiceImpl; +import org.objectstyle.di.service.SubService; +import org.objectstyle.di.service.SubServiceImpl; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.stereotype.Component; + +@Component +public class Main { + + @Bean + public Service service(SubService subService) { + return new ServiceImpl(subService); + } + + @Bean + public SubService subService() { + return new SubServiceImpl(); + } + + public static void main(String[] args) { + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Main.class); + System.out.println(context.getBean(Service.class).doIt()); + } +} \ No newline at end of file