diff --git a/aws-lambda/pom.xml b/aws-lambda/pom.xml
index 3a2be70da6..c47c3cd86f 100644
--- a/aws-lambda/pom.xml
+++ b/aws-lambda/pom.xml
@@ -95,7 +95,6 @@
2.8.2
1.11.241
3.0.0
- 2.10
\ No newline at end of file
diff --git a/aws/pom.xml b/aws/pom.xml
index 26bc0c8037..ab63f6afa1 100644
--- a/aws/pom.xml
+++ b/aws/pom.xml
@@ -100,26 +100,6 @@
-
-
- org.apache.maven.plugins
- maven-dependency-plugin
- ${maven-dependency-plugin.version}
-
-
- copy-dependencies
- test-compile
-
- copy-dependencies
-
-
- test
- so,dll,dylib
- ${project.basedir}/native-libs
-
-
-
-
@@ -144,7 +124,6 @@
1.10.L001
0.9.4.0006L
3.0.0
- 2.10
\ No newline at end of file
diff --git a/checker-plugin/pom.xml b/checker-plugin/pom.xml
index 7538340f69..45f0939e77 100644
--- a/checker-plugin/pom.xml
+++ b/checker-plugin/pom.xml
@@ -41,27 +41,6 @@
-
-
- org.apache.maven.plugins
- maven-dependency-plugin
-
-
-
-
- properties
-
-
-
-
-
maven-compiler-plugin
${maven-compiler-plugin.version}
diff --git a/core-java-8/pom.xml b/core-java-8/pom.xml
index fa0d79e405..18bdaa15f4 100644
--- a/core-java-8/pom.xml
+++ b/core-java-8/pom.xml
@@ -116,23 +116,6 @@
-
- org.apache.maven.plugins
- maven-dependency-plugin
-
-
- copy-dependencies
- prepare-package
-
- copy-dependencies
-
-
- ${project.build.directory}/libs
-
-
-
-
-
org.apache.maven.plugins
maven-compiler-plugin
diff --git a/core-java-concurrency-collections/pom.xml b/core-java-concurrency-collections/pom.xml
index 5e0a80d33c..9473de8c51 100644
--- a/core-java-concurrency-collections/pom.xml
+++ b/core-java-concurrency-collections/pom.xml
@@ -57,26 +57,6 @@
true
-
-
-
- org.apache.maven.plugins
- maven-dependency-plugin
-
-
- copy-dependencies
- prepare-package
-
- copy-dependencies
-
-
- ${project.build.directory}/libs
-
-
-
-
-
-
diff --git a/core-java-concurrency/pom.xml b/core-java-concurrency/pom.xml
index eb81983a2a..bd22253c2c 100644
--- a/core-java-concurrency/pom.xml
+++ b/core-java-concurrency/pom.xml
@@ -57,26 +57,6 @@
true
-
-
-
- org.apache.maven.plugins
- maven-dependency-plugin
-
-
- copy-dependencies
- prepare-package
-
- copy-dependencies
-
-
- ${project.build.directory}/libs
-
-
-
-
-
-
diff --git a/core-java-sun/pom.xml b/core-java-sun/pom.xml
index 7292335232..57d5e9da5b 100644
--- a/core-java-sun/pom.xml
+++ b/core-java-sun/pom.xml
@@ -166,22 +166,6 @@
-
- org.apache.maven.plugins
- maven-dependency-plugin
-
-
- copy-dependencies
- prepare-package
-
- copy-dependencies
-
-
- ${project.build.directory}/libs
-
-
-
-
org.apache.maven.plugins
maven-jar-plugin
diff --git a/core-java/src/main/java/com/baeldung/decimalformat/DoubletoString.java b/core-java/src/main/java/com/baeldung/decimalformat/DoubletoString.java
new file mode 100644
index 0000000000..87d10a3548
--- /dev/null
+++ b/core-java/src/main/java/com/baeldung/decimalformat/DoubletoString.java
@@ -0,0 +1,38 @@
+package com.baeldung.decimalformat;
+
+ import java.math.RoundingMode;
+ import java.text.DecimalFormat;
+ import java.text.NumberFormat;
+ import java.util.Locale;
+
+ public class DoubletoString {
+
+ public static void main(String[] args) {
+
+ double doubleValue = 345.56;
+
+ System.out.println(String.valueOf((int) doubleValue));
+
+ System.out.println(String.format("%.0f", doubleValue));
+
+ doubleValue = Math.floor(doubleValue);
+ DecimalFormat df = new DecimalFormat("#");
+ df.setRoundingMode(RoundingMode.FLOOR);
+ System.out.println(df.format(doubleValue));
+
+ Locale enlocale = new Locale("en", "US");
+ String pattern = "###,##";
+ df = (DecimalFormat) NumberFormat.getNumberInstance(enlocale);
+ df.applyPattern(pattern);
+ String format = df.format(doubleValue);
+ System.out.println(format);
+
+ Locale dalocale = new Locale("da", "DK");
+ df = (DecimalFormat) NumberFormat.getNumberInstance(dalocale);
+ df.applyPattern(pattern);
+ System.out.println(df.format(doubleValue));
+
+
+ }
+
+ }
diff --git a/core-kotlin/README.md b/core-kotlin/README.md
index dc8b299165..f63451bc02 100644
--- a/core-kotlin/README.md
+++ b/core-kotlin/README.md
@@ -8,7 +8,6 @@
- [Generics in Kotlin](http://www.baeldung.com/kotlin-generics)
- [Introduction to Kotlin Coroutines](http://www.baeldung.com/kotlin-coroutines)
- [Destructuring Declarations in Kotlin](http://www.baeldung.com/kotlin-destructuring-declarations)
-- [Kotlin with Mockito](http://www.baeldung.com/kotlin-mockito)
- [Lazy Initialization in Kotlin](http://www.baeldung.com/kotlin-lazy-initialization)
- [Overview of Kotlin Collections API](http://www.baeldung.com/kotlin-collections-api)
- [Converting a List to Map in Kotlin](http://www.baeldung.com/kotlin-list-to-map)
@@ -19,8 +18,6 @@
- [Extension Methods in Kotlin](http://www.baeldung.com/kotlin-extension-methods)
- [Infix Functions in Kotlin](http://www.baeldung.com/kotlin-infix-functions)
- [Try-with-resources in Kotlin](http://www.baeldung.com/kotlin-try-with-resources)
-- [HTTP Requests with Kotlin and khttp](http://www.baeldung.com/kotlin-khttp)
-- [Kotlin Dependency Injection with Kodein](http://www.baeldung.com/kotlin-kodein-dependency-injection)
- [Regular Expressions in Kotlin](http://www.baeldung.com/kotlin-regular-expressions)
- [Objects in Kotlin](http://www.baeldung.com/kotlin-objects)
- [Reading from a File in Kotlin](http://www.baeldung.com/kotlin-read-file)
@@ -28,11 +25,7 @@
- [Filtering Kotlin Collections](http://www.baeldung.com/kotlin-filter-collection)
- [Writing to a File in Kotlin](http://www.baeldung.com/kotlin-write-file)
- [Lambda Expressions in Kotlin](http://www.baeldung.com/kotlin-lambda-expressions)
-- [Writing Specifications with Kotlin and Spek](http://www.baeldung.com/kotlin-spek)
-- [Processing JSON with Kotlin and Klaxson](http://www.baeldung.com/kotlin-json-klaxson)
- [Kotlin String Templates](http://www.baeldung.com/kotlin-string-template)
-- [Java EE 8 Security API](http://www.baeldung.com/java-ee-8-security)
-- [Kotlin with Ktor](http://www.baeldung.com/kotlin-ktor)
- [Working with Enums in Kotlin](http://www.baeldung.com/kotlin-enum)
- [Create a Java and Kotlin Project with Maven](http://www.baeldung.com/kotlin-maven-java-project)
- [Reflection with Kotlin](http://www.baeldung.com/kotlin-reflection)
@@ -40,5 +33,4 @@
- [Idiomatic Logging in Kotlin](http://www.baeldung.com/kotlin-logging)
- [Kotlin Constructors](https://www.baeldung.com/kotlin-constructors)
- [Creational Design Patterns in Kotlin: Builder](https://www.baeldung.com/kotlin-builder-pattern)
-- [Kotlin Nested and Inner Classes](https://www.baeldung.com/kotlin-inner-classes)
-- [Guide to the Kotlin Exposed Framework](https://www.baeldung.com/kotlin-exposed-persistence)
+- [Kotlin Nested and Inner Classes](https://www.baeldung.com/kotlin-inner-classes)
\ No newline at end of file
diff --git a/core-kotlin/build.gradle b/core-kotlin/build.gradle
index 6c1e06aa25..2b6527fca7 100755
--- a/core-kotlin/build.gradle
+++ b/core-kotlin/build.gradle
@@ -6,7 +6,6 @@ version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.2.41'
- ext.ktor_version = '0.9.2'
repositories {
mavenCentral()
@@ -44,14 +43,6 @@ sourceSets {
}
dependencies {
- compile "io.ktor:ktor-server-netty:$ktor_version"
compile "ch.qos.logback:logback-classic:1.2.1"
- compile "io.ktor:ktor-gson:$ktor_version"
testCompile group: 'junit', name: 'junit', version: '4.12'
- implementation 'com.beust:klaxon:3.0.1'
-
-}
-task runServer(type: JavaExec) {
- main = 'APIServer'
- classpath = sourceSets.main.runtimeClasspath
}
\ No newline at end of file
diff --git a/core-kotlin/kotlin-ktor/webapp/WEB-INF/web.xml b/core-kotlin/kotlin-ktor/webapp/WEB-INF/web.xml
deleted file mode 100755
index 513a80cb27..0000000000
--- a/core-kotlin/kotlin-ktor/webapp/WEB-INF/web.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-
-
-
-
-
-
- io.ktor.ktor.config
- application.conf
-
-
-
- KtorServlet
- KtorServlet
- io.ktor.server.servlet.ServletApplicationEngine
-
-
- true
-
-
-
- 304857600
- 304857600
- 0
-
-
-
-
- KtorServlet
- /
-
-
-
\ No newline at end of file
diff --git a/core-kotlin/pom.xml b/core-kotlin/pom.xml
index 88f54963ed..70cbd67645 100644
--- a/core-kotlin/pom.xml
+++ b/core-kotlin/pom.xml
@@ -12,33 +12,7 @@
../parent-kotlin
-
-
- exposed
- exposed
- https://dl.bintray.com/kotlin/exposed
-
-
-
-
- org.jetbrains.spek
- spek-api
- 1.1.5
- test
-
-
- org.jetbrains.spek
- spek-subject-extension
- 1.1.5
- test
-
-
- org.jetbrains.spek
- spek-junit-platform-engine
- 1.1.5
- test
-
org.apache.commons
commons-math3
@@ -50,38 +24,12 @@
${junit.platform.version}
test
-
- khttp
- khttp
- ${khttp.version}
-
-
- com.nhaarman
- mockito-kotlin
- ${mockito-kotlin.version}
- test
-
-
- com.github.salomonbrys.kodein
- kodein
- ${kodein.version}
-
org.assertj
assertj-core
${assertj.version}
test
-
- com.beust
- klaxon
- ${klaxon.version}
-
-
- org.jetbrains.exposed
- exposed
- ${exposed.version}
-
com.h2database
h2
@@ -110,16 +58,11 @@
- 1.5.0
- 4.1.0
- 3.0.4
- 0.1.0
3.6.1
1.1.1
5.2.0
3.10.0
1.4.197
- 0.10.4
1.15.0
diff --git a/core-kotlin/src/main/kotlin/com/baeldung/ktor/APIServer.kt b/core-kotlin/src/main/kotlin/com/baeldung/ktor/APIServer.kt
deleted file mode 100755
index a12182ccc8..0000000000
--- a/core-kotlin/src/main/kotlin/com/baeldung/ktor/APIServer.kt
+++ /dev/null
@@ -1,73 +0,0 @@
-@file:JvmName("APIServer")
-
-
-import io.ktor.application.call
-import io.ktor.application.install
-import io.ktor.features.CallLogging
-import io.ktor.features.ContentNegotiation
-import io.ktor.features.DefaultHeaders
-import io.ktor.gson.gson
-import io.ktor.request.path
-import io.ktor.request.receive
-import io.ktor.response.respond
-import io.ktor.routing.*
-import io.ktor.server.engine.embeddedServer
-import io.ktor.server.netty.Netty
-import org.slf4j.event.Level
-
-data class Author(val name: String, val website: String)
-data class ToDo(var id: Int, val name: String, val description: String, val completed: Boolean)
-
-fun main(args: Array) {
-
- val toDoList = ArrayList();
- val jsonResponse = """{
- "id": 1,
- "task": "Pay waterbill",
- "description": "Pay water bill today",
- }"""
-
-
- embeddedServer(Netty, 8080) {
- install(DefaultHeaders) {
- header("X-Developer", "Baeldung")
- }
- install(CallLogging) {
- level = Level.DEBUG
- filter { call -> call.request.path().startsWith("/todo") }
- filter { call -> call.request.path().startsWith("/author") }
- }
- install(ContentNegotiation) {
- gson {
- setPrettyPrinting()
- }
- }
- routing() {
- route("/todo") {
- post {
- var toDo = call.receive();
- toDo.id = toDoList.size;
- toDoList.add(toDo);
- call.respond("Added")
-
- }
- delete("/{id}") {
- call.respond(toDoList.removeAt(call.parameters["id"]!!.toInt()));
- }
- get("/{id}") {
-
- call.respond(toDoList[call.parameters["id"]!!.toInt()]);
- }
- get {
- call.respond(toDoList);
- }
- }
- get("/author"){
- call.respond(Author("Baeldung","baeldung.com"));
-
- }
-
-
- }
- }.start(wait = true)
-}
\ No newline at end of file
diff --git a/disruptor/pom.xml b/disruptor/pom.xml
index d3cef3bd9b..c26dcc0cd4 100644
--- a/disruptor/pom.xml
+++ b/disruptor/pom.xml
@@ -36,22 +36,6 @@
-
- org.apache.maven.plugins
- maven-dependency-plugin
-
-
- copy-dependencies
- prepare-package
-
- copy-dependencies
-
-
- ${project.build.directory}/libs
-
-
-
-
org.apache.maven.plugins
maven-jar-plugin
diff --git a/java-dates/pom.xml b/java-dates/pom.xml
index 877dd615a8..13e2a077e1 100644
--- a/java-dates/pom.xml
+++ b/java-dates/pom.xml
@@ -61,23 +61,6 @@
-
- org.apache.maven.plugins
- maven-dependency-plugin
-
-
- copy-dependencies
- prepare-package
-
- copy-dependencies
-
-
- ${project.build.directory}/libs
-
-
-
-
-
org.apache.maven.plugins
maven-compiler-plugin
diff --git a/java-numbers/pom.xml b/java-numbers/pom.xml
index bf4d3e8792..bb63c8cfe1 100644
--- a/java-numbers/pom.xml
+++ b/java-numbers/pom.xml
@@ -83,23 +83,6 @@
-
- org.apache.maven.plugins
- maven-dependency-plugin
-
-
- copy-dependencies
- prepare-package
-
- copy-dependencies
-
-
- ${project.build.directory}/libs
-
-
-
-
-
org.apache.maven.plugins
maven-javadoc-plugin
diff --git a/java-numbers/src/main/java/com/baeldung/maths/BigDecimalDemo.java b/java-numbers/src/main/java/com/baeldung/maths/BigDecimalDemo.java
new file mode 100644
index 0000000000..7de0197769
--- /dev/null
+++ b/java-numbers/src/main/java/com/baeldung/maths/BigDecimalDemo.java
@@ -0,0 +1,29 @@
+package com.baeldung.maths;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+
+public class BigDecimalDemo {
+
+ /** Calculate total amount to be paid for an item rounded to cents..
+ * @param quantity
+ * @param unitPrice
+ * @param discountRate
+ * @param taxRate
+ * @return
+ */
+ public static BigDecimal calculateTotalAmount(BigDecimal quantity,
+ BigDecimal unitPrice, BigDecimal discountRate, BigDecimal taxRate) {
+ BigDecimal amount = quantity.multiply(unitPrice);
+ BigDecimal discount = amount.multiply(discountRate);
+ BigDecimal discountedAmount = amount.subtract(discount);
+ BigDecimal tax = discountedAmount.multiply(taxRate);
+ BigDecimal total = discountedAmount.add(tax);
+
+ // round to 2 decimal places using HALF_EVEN
+ BigDecimal roundedTotal = total.setScale(2, RoundingMode.HALF_EVEN);
+
+ return roundedTotal;
+ }
+
+}
diff --git a/java-numbers/src/test/java/com/baeldung/maths/BigDecimalDemoUnitTest.java b/java-numbers/src/test/java/com/baeldung/maths/BigDecimalDemoUnitTest.java
new file mode 100644
index 0000000000..2bf9872bec
--- /dev/null
+++ b/java-numbers/src/test/java/com/baeldung/maths/BigDecimalDemoUnitTest.java
@@ -0,0 +1,120 @@
+package com.baeldung.maths;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.math.MathContext;
+import java.math.RoundingMode;
+import java.util.Random;
+
+import org.junit.jupiter.api.Test;
+
+public class BigDecimalDemoUnitTest {
+
+ @Test
+ public void whenBigDecimalCreated_thenValueMatches() {
+ BigDecimal bdFromString = new BigDecimal("0.1");
+ BigDecimal bdFromCharArray = new BigDecimal(
+ new char[] { '3', '.', '1', '6', '1', '5' });
+ BigDecimal bdlFromInt = new BigDecimal(42);
+ BigDecimal bdFromLong = new BigDecimal(123412345678901L);
+ BigInteger bigInteger = BigInteger.probablePrime(100, new Random());
+ BigDecimal bdFromBigInteger = new BigDecimal(bigInteger);
+
+ assertEquals("0.1", bdFromString.toString());
+ assertEquals("3.1615", bdFromCharArray.toString());
+ assertEquals("42", bdlFromInt.toString());
+ assertEquals("123412345678901", bdFromLong.toString());
+ assertEquals(bigInteger.toString(), bdFromBigInteger.toString());
+ }
+
+ @Test
+ public void whenBigDecimalCreatedFromDouble_thenValueMayNotMatch() {
+ BigDecimal bdFromDouble = new BigDecimal(0.1d);
+ assertNotEquals("0.1", bdFromDouble.toString());
+ }
+
+ @Test
+ public void whenBigDecimalCreatedUsingValueOf_thenValueMatches() {
+ BigDecimal bdFromLong1 = BigDecimal.valueOf(123412345678901L);
+ BigDecimal bdFromLong2 = BigDecimal.valueOf(123412345678901L, 2);
+ BigDecimal bdFromDouble = BigDecimal.valueOf(0.1d);
+
+ assertEquals("123412345678901", bdFromLong1.toString());
+ assertEquals("1234123456789.01", bdFromLong2.toString());
+ assertEquals("0.1", bdFromDouble.toString());
+ }
+
+ @Test
+ public void whenEqualsCalled_thenSizeAndScaleMatched() {
+ BigDecimal bd1 = new BigDecimal("1.0");
+ BigDecimal bd2 = new BigDecimal("1.00");
+
+ assertFalse(bd1.equals(bd2));
+ }
+
+ @Test
+ public void whenComparingBigDecimals_thenExpectedResult() {
+ BigDecimal bd1 = new BigDecimal("1.0");
+ BigDecimal bd2 = new BigDecimal("1.00");
+ BigDecimal bd3 = new BigDecimal("2.0");
+
+ assertTrue(bd1.compareTo(bd3) < 0);
+ assertTrue(bd3.compareTo(bd1) > 0);
+ assertTrue(bd1.compareTo(bd2) == 0);
+ assertTrue(bd1.compareTo(bd3) <= 0);
+ assertTrue(bd1.compareTo(bd2) >= 0);
+ assertTrue(bd1.compareTo(bd3) != 0);
+ }
+
+ @Test
+ public void whenPerformingArithmetic_thenExpectedResult() {
+ BigDecimal bd1 = new BigDecimal("4.0");
+ BigDecimal bd2 = new BigDecimal("2.0");
+
+ BigDecimal sum = bd1.add(bd2);
+ BigDecimal difference = bd1.subtract(bd2);
+ BigDecimal quotient = bd1.divide(bd2);
+ BigDecimal product = bd1.multiply(bd2);
+
+ assertTrue(sum.compareTo(new BigDecimal("6.0")) == 0);
+ assertTrue(difference.compareTo(new BigDecimal("2.0")) == 0);
+ assertTrue(quotient.compareTo(new BigDecimal("2.0")) == 0);
+ assertTrue(product.compareTo(new BigDecimal("8.0")) == 0);
+ }
+
+ @Test
+ public void whenGettingAttributes_thenExpectedResult() {
+ BigDecimal bd = new BigDecimal("-12345.6789");
+
+ assertEquals(9, bd.precision());
+ assertEquals(4, bd.scale());
+ assertEquals(-1, bd.signum());
+ }
+
+ @Test
+ public void whenRoundingDecimal_thenExpectedResult() {
+ BigDecimal bd = new BigDecimal("2.5");
+ // Round to 1 digit using HALF_EVEN
+ BigDecimal rounded = bd
+ .round(new MathContext(1, RoundingMode.HALF_EVEN));
+
+ assertEquals("2", rounded.toString());
+ }
+
+ @Test
+ public void givenPurchaseTxn_whenCalculatingTotalAmount_thenExpectedResult() {
+ BigDecimal quantity = new BigDecimal("4.5");
+ BigDecimal unitPrice = new BigDecimal("2.69");
+ BigDecimal discountRate = new BigDecimal("0.10");
+ BigDecimal taxRate = new BigDecimal("0.0725");
+
+ BigDecimal amountToBePaid = BigDecimalDemo
+ .calculateTotalAmount(quantity, unitPrice, discountRate, taxRate);
+ assertEquals("11.68", amountToBePaid.toString());
+ }
+}
diff --git a/java-numbers/src/test/java/com/baeldung/maths/BigIntegerDemoUnitTest.java b/java-numbers/src/test/java/com/baeldung/maths/BigIntegerDemoUnitTest.java
new file mode 100644
index 0000000000..3537ccb3a3
--- /dev/null
+++ b/java-numbers/src/test/java/com/baeldung/maths/BigIntegerDemoUnitTest.java
@@ -0,0 +1,128 @@
+package com.baeldung.maths;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.math.BigInteger;
+import java.util.Random;
+
+import org.junit.jupiter.api.Test;
+
+public class BigIntegerDemoUnitTest {
+
+ @Test
+ public void whenBigIntegerCreatedFromConstructor_thenExpectedResult() {
+ BigInteger biFromString = new BigInteger("1234567890987654321");
+ BigInteger biFromByteArray = new BigInteger(
+ new byte[] { 64, 64, 64, 64, 64, 64 });
+ BigInteger biFromSignMagnitude = new BigInteger(-1,
+ new byte[] { 64, 64, 64, 64, 64, 64 });
+
+ assertEquals("1234567890987654321", biFromString.toString());
+ assertEquals("70644700037184", biFromByteArray.toString());
+ assertEquals("-70644700037184", biFromSignMagnitude.toString());
+ }
+
+ @Test
+ public void whenLongConvertedToBigInteger_thenValueMatches() {
+ BigInteger bi = BigInteger.valueOf(2305843009213693951L);
+
+ assertEquals("2305843009213693951", bi.toString());
+ }
+
+ @Test
+ public void givenBigIntegers_whentCompared_thenExpectedResult() {
+ BigInteger i = new BigInteger("123456789012345678901234567890");
+ BigInteger j = new BigInteger("123456789012345678901234567891");
+ BigInteger k = new BigInteger("123456789012345678901234567892");
+
+ assertTrue(i.compareTo(i) == 0);
+ assertTrue(j.compareTo(i) > 0);
+ assertTrue(j.compareTo(k) < 0);
+ }
+
+ @Test
+ public void givenBigIntegers_whenPerformingArithmetic_thenExpectedResult() {
+ BigInteger i = new BigInteger("4");
+ BigInteger j = new BigInteger("2");
+
+ BigInteger sum = i.add(j);
+ BigInteger difference = i.subtract(j);
+ BigInteger quotient = i.divide(j);
+ BigInteger product = i.multiply(j);
+
+ assertEquals(new BigInteger("6"), sum);
+ assertEquals(new BigInteger("2"), difference);
+ assertEquals(new BigInteger("2"), quotient);
+ assertEquals(new BigInteger("8"), product);
+ }
+
+ @Test
+ public void givenBigIntegers_whenPerformingBitOperations_thenExpectedResult() {
+ BigInteger i = new BigInteger("17");
+ BigInteger j = new BigInteger("7");
+
+ BigInteger and = i.and(j);
+ BigInteger or = i.or(j);
+ BigInteger not = j.not();
+ BigInteger xor = i.xor(j);
+ BigInteger andNot = i.andNot(j);
+ BigInteger shiftLeft = i.shiftLeft(1);
+ BigInteger shiftRight = i.shiftRight(1);
+
+ assertEquals(new BigInteger("1"), and);
+ assertEquals(new BigInteger("23"), or);
+ assertEquals(new BigInteger("-8"), not);
+ assertEquals(new BigInteger("22"), xor);
+ assertEquals(new BigInteger("16"), andNot);
+ assertEquals(new BigInteger("34"), shiftLeft);
+ assertEquals(new BigInteger("8"), shiftRight);
+ }
+
+ @Test
+ public void givenBigIntegers_whenPerformingBitManipulations_thenExpectedResult() {
+ BigInteger i = new BigInteger("1018");
+
+ int bitCount = i.bitCount();
+ int bitLength = i.bitLength();
+ int getLowestSetBit = i.getLowestSetBit();
+ boolean testBit3 = i.testBit(3);
+ BigInteger setBit12 = i.setBit(12);
+ BigInteger flipBit0 = i.flipBit(0);
+ BigInteger clearBit3 = i.clearBit(3);
+
+ assertEquals(8, bitCount);
+ assertEquals(10, bitLength);
+ assertEquals(1, getLowestSetBit);
+ assertEquals(true, testBit3);
+ assertEquals(new BigInteger("5114"), setBit12);
+ assertEquals(new BigInteger("1019"), flipBit0);
+ assertEquals(new BigInteger("1010"), clearBit3);
+ }
+
+ @Test
+ public void givenBigIntegers_whenModularCalculation_thenExpectedResult() {
+ BigInteger i = new BigInteger("31");
+ BigInteger j = new BigInteger("24");
+ BigInteger k = new BigInteger("16");
+
+ BigInteger gcd = j.gcd(k);
+ BigInteger multiplyAndmod = j.multiply(k)
+ .mod(i);
+ BigInteger modInverse = j.modInverse(i);
+ BigInteger modPow = j.modPow(k, i);
+
+ assertEquals(new BigInteger("8"), gcd);
+ assertEquals(new BigInteger("12"), multiplyAndmod);
+ assertEquals(new BigInteger("22"), modInverse);
+ assertEquals(new BigInteger("7"), modPow);
+ }
+
+ @Test
+ public void givenBigIntegers_whenPrimeOperations_thenExpectedResult() {
+ BigInteger i = BigInteger.probablePrime(100, new Random());
+
+ boolean isProbablePrime = i.isProbablePrime(1000);
+ assertEquals(true, isProbablePrime);
+ }
+}
diff --git a/java-streams/pom.xml b/java-streams/pom.xml
index 4f8651a756..023a5f695b 100644
--- a/java-streams/pom.xml
+++ b/java-streams/pom.xml
@@ -86,23 +86,6 @@
-
- org.apache.maven.plugins
- maven-dependency-plugin
-
-
- copy-dependencies
- prepare-package
-
- copy-dependencies
-
-
- ${project.build.directory}/libs
-
-
-
-
-
org.apache.maven.plugins
maven-compiler-plugin
diff --git a/java-strings/README.md b/java-strings/README.md
index 04f15136c9..233d986d98 100644
--- a/java-strings/README.md
+++ b/java-strings/README.md
@@ -26,3 +26,4 @@
- [Convert a String to Title Case](http://www.baeldung.com/java-string-title-case)
- [Compact Strings in Java 9](http://www.baeldung.com/java-9-compact-string)
- [Java Check a String for Lowercase/Uppercase Letter, Special Character and Digit](https://www.baeldung.com/java-lowercase-uppercase-special-character-digit-regex)
+- [Convert java.util.Date to String](https://www.baeldung.com/java-util-date-to-string)
diff --git a/java-strings/pom.xml b/java-strings/pom.xml
index 0c83b4d9e7..2afe18f07a 100644
--- a/java-strings/pom.xml
+++ b/java-strings/pom.xml
@@ -71,23 +71,6 @@
-
- org.apache.maven.plugins
- maven-dependency-plugin
-
-
- copy-dependencies
- prepare-package
-
- copy-dependencies
-
-
- ${project.build.directory}/libs
-
-
-
-
-
org.apache.maven.plugins
maven-compiler-plugin
diff --git a/core-kotlin/kotlin-ktor/.gitignore b/kotlin-libraries/.gitignore
similarity index 100%
rename from core-kotlin/kotlin-ktor/.gitignore
rename to kotlin-libraries/.gitignore
diff --git a/kotlin-libraries/README.md b/kotlin-libraries/README.md
new file mode 100644
index 0000000000..ce30c71792
--- /dev/null
+++ b/kotlin-libraries/README.md
@@ -0,0 +1,10 @@
+## Relevant articles:
+
+- [Kotlin with Mockito](http://www.baeldung.com/kotlin-mockito)
+- [HTTP Requests with Kotlin and khttp](http://www.baeldung.com/kotlin-khttp)
+- [Kotlin Dependency Injection with Kodein](http://www.baeldung.com/kotlin-kodein-dependency-injection)
+- [Writing Specifications with Kotlin and Spek](http://www.baeldung.com/kotlin-spek)
+- [Processing JSON with Kotlin and Klaxson](http://www.baeldung.com/kotlin-json-klaxson)
+- [Kotlin with Ktor](http://www.baeldung.com/kotlin-ktor)
+- [Idiomatic Logging in Kotlin](http://www.baeldung.com/kotlin-logging)
+- [Guide to the Kotlin Exposed Framework](https://www.baeldung.com/kotlin-exposed-persistence)
\ No newline at end of file
diff --git a/core-kotlin/kotlin-ktor/build.gradle b/kotlin-libraries/build.gradle
old mode 100755
new mode 100644
similarity index 83%
rename from core-kotlin/kotlin-ktor/build.gradle
rename to kotlin-libraries/build.gradle
index 5c8f523cf1..b244df34b0
--- a/core-kotlin/kotlin-ktor/build.gradle
+++ b/kotlin-libraries/build.gradle
@@ -1,47 +1,57 @@
-
-
-group 'com.baeldung.ktor'
-version '1.0-SNAPSHOT'
-
-
-buildscript {
- ext.kotlin_version = '1.2.41'
- ext.ktor_version = '0.9.2'
-
- repositories {
- mavenCentral()
- }
- dependencies {
- classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
- }
-}
-
-apply plugin: 'java'
-apply plugin: 'kotlin'
-apply plugin: 'application'
-
-mainClassName = 'APIServer.kt'
-
-sourceCompatibility = 1.8
-compileKotlin { kotlinOptions.jvmTarget = "1.8" }
-compileTestKotlin { kotlinOptions.jvmTarget = "1.8" }
-
-kotlin { experimental { coroutines "enable" } }
-
-repositories {
- mavenCentral()
- jcenter()
- maven { url "https://dl.bintray.com/kotlin/ktor" }
-}
-
-dependencies {
- compile "io.ktor:ktor-server-netty:$ktor_version"
- compile "ch.qos.logback:logback-classic:1.2.1"
- compile "io.ktor:ktor-gson:$ktor_version"
- testCompile group: 'junit', name: 'junit', version: '4.12'
-
-}
-task runServer(type: JavaExec) {
- main = 'APIServer'
- classpath = sourceSets.main.runtimeClasspath
+
+
+group 'com.baeldung.ktor'
+version '1.0-SNAPSHOT'
+
+
+buildscript {
+ ext.kotlin_version = '1.2.41'
+ ext.ktor_version = '0.9.2'
+
+ repositories {
+ mavenCentral()
+ }
+ dependencies {
+
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
+ }
+}
+
+apply plugin: 'java'
+apply plugin: 'kotlin'
+apply plugin: 'application'
+
+mainClassName = 'APIServer.kt'
+
+sourceCompatibility = 1.8
+compileKotlin { kotlinOptions.jvmTarget = "1.8" }
+compileTestKotlin { kotlinOptions.jvmTarget = "1.8" }
+
+kotlin { experimental { coroutines "enable" } }
+
+repositories {
+ mavenCentral()
+ jcenter()
+ maven { url "https://dl.bintray.com/kotlin/ktor" }
+}
+sourceSets {
+ main{
+ kotlin{
+ srcDirs 'com/baeldung/ktor'
+ }
+ }
+
+}
+
+dependencies {
+ compile "io.ktor:ktor-server-netty:$ktor_version"
+ compile "ch.qos.logback:logback-classic:1.2.1"
+ compile "io.ktor:ktor-gson:$ktor_version"
+ testCompile group: 'junit', name: 'junit', version: '4.12'
+ implementation 'com.beust:klaxon:3.0.1'
+
+}
+task runServer(type: JavaExec) {
+ main = 'APIServer'
+ classpath = sourceSets.main.runtimeClasspath
}
\ No newline at end of file
diff --git a/core-kotlin/kotlin-ktor/gradle/wrapper/gradle-wrapper.jar b/kotlin-libraries/gradle/wrapper/gradle-wrapper.jar
old mode 100755
new mode 100644
similarity index 100%
rename from core-kotlin/kotlin-ktor/gradle/wrapper/gradle-wrapper.jar
rename to kotlin-libraries/gradle/wrapper/gradle-wrapper.jar
diff --git a/core-kotlin/kotlin-ktor/gradle/wrapper/gradle-wrapper.properties b/kotlin-libraries/gradle/wrapper/gradle-wrapper.properties
old mode 100755
new mode 100644
similarity index 97%
rename from core-kotlin/kotlin-ktor/gradle/wrapper/gradle-wrapper.properties
rename to kotlin-libraries/gradle/wrapper/gradle-wrapper.properties
index 0b83b5a3e3..933b6473ce
--- a/core-kotlin/kotlin-ktor/gradle/wrapper/gradle-wrapper.properties
+++ b/kotlin-libraries/gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,5 @@
-distributionBase=GRADLE_USER_HOME
-distributionPath=wrapper/dists
-zipStoreBase=GRADLE_USER_HOME
-zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-bin.zip
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-bin.zip
diff --git a/core-kotlin/kotlin-ktor/gradlew b/kotlin-libraries/gradlew
old mode 100755
new mode 100644
similarity index 100%
rename from core-kotlin/kotlin-ktor/gradlew
rename to kotlin-libraries/gradlew
diff --git a/core-kotlin/kotlin-ktor/gradlew.bat b/kotlin-libraries/gradlew.bat
old mode 100755
new mode 100644
similarity index 96%
rename from core-kotlin/kotlin-ktor/gradlew.bat
rename to kotlin-libraries/gradlew.bat
index e95643d6a2..f9553162f1
--- a/core-kotlin/kotlin-ktor/gradlew.bat
+++ b/kotlin-libraries/gradlew.bat
@@ -1,84 +1,84 @@
-@if "%DEBUG%" == "" @echo off
-@rem ##########################################################################
-@rem
-@rem Gradle startup script for Windows
-@rem
-@rem ##########################################################################
-
-@rem Set local scope for the variables with windows NT shell
-if "%OS%"=="Windows_NT" setlocal
-
-set DIRNAME=%~dp0
-if "%DIRNAME%" == "" set DIRNAME=.
-set APP_BASE_NAME=%~n0
-set APP_HOME=%DIRNAME%
-
-@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
-set DEFAULT_JVM_OPTS=
-
-@rem Find java.exe
-if defined JAVA_HOME goto findJavaFromJavaHome
-
-set JAVA_EXE=java.exe
-%JAVA_EXE% -version >NUL 2>&1
-if "%ERRORLEVEL%" == "0" goto init
-
-echo.
-echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
-
-goto fail
-
-:findJavaFromJavaHome
-set JAVA_HOME=%JAVA_HOME:"=%
-set JAVA_EXE=%JAVA_HOME%/bin/java.exe
-
-if exist "%JAVA_EXE%" goto init
-
-echo.
-echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
-
-goto fail
-
-:init
-@rem Get command-line arguments, handling Windows variants
-
-if not "%OS%" == "Windows_NT" goto win9xME_args
-
-:win9xME_args
-@rem Slurp the command line arguments.
-set CMD_LINE_ARGS=
-set _SKIP=2
-
-:win9xME_args_slurp
-if "x%~1" == "x" goto execute
-
-set CMD_LINE_ARGS=%*
-
-:execute
-@rem Setup the command line
-
-set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
-
-@rem Execute Gradle
-"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
-
-:end
-@rem End local scope for the variables with windows NT shell
-if "%ERRORLEVEL%"=="0" goto mainEnd
-
-:fail
-rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
-rem the _cmd.exe /c_ return code!
-if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
-exit /b 1
-
-:mainEnd
-if "%OS%"=="Windows_NT" endlocal
-
-:omega
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windows variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/kotlin-libraries/pom.xml b/kotlin-libraries/pom.xml
new file mode 100644
index 0000000000..c5b7fed951
--- /dev/null
+++ b/kotlin-libraries/pom.xml
@@ -0,0 +1,105 @@
+
+
+ 4.0.0
+ kotlin-libraries
+ jar
+
+
+ com.baeldung
+ parent-kotlin
+ 1.0.0-SNAPSHOT
+ ../parent-kotlin
+
+
+
+
+ exposed
+ exposed
+ https://dl.bintray.com/kotlin/exposed
+
+
+
+
+
+ org.jetbrains.spek
+ spek-api
+ 1.1.5
+ test
+
+
+ org.jetbrains.spek
+ spek-subject-extension
+ 1.1.5
+ test
+
+
+ org.jetbrains.spek
+ spek-junit-platform-engine
+ 1.1.5
+ test
+
+
+ org.apache.commons
+ commons-math3
+ ${commons-math3.version}
+
+
+ org.junit.platform
+ junit-platform-runner
+ ${junit.platform.version}
+ test
+
+
+ khttp
+ khttp
+ ${khttp.version}
+
+
+ com.nhaarman
+ mockito-kotlin
+ ${mockito-kotlin.version}
+ test
+
+
+ com.github.salomonbrys.kodein
+ kodein
+ ${kodein.version}
+
+
+ org.assertj
+ assertj-core
+ ${assertj.version}
+ test
+
+
+ com.beust
+ klaxon
+ ${klaxon.version}
+
+
+ org.jetbrains.exposed
+ exposed
+ ${exposed.version}
+
+
+ com.h2database
+ h2
+ ${h2database.version}
+
+
+
+
+ 1.5.0
+ 4.1.0
+ 3.0.4
+ 0.1.0
+ 3.6.1
+ 1.1.1
+ 5.2.0
+ 3.10.0
+ 1.4.197
+ 0.10.4
+
+
+
\ No newline at end of file
diff --git a/core-kotlin/kotlin-ktor/resources/logback.xml b/kotlin-libraries/resources/logback.xml
old mode 100755
new mode 100644
similarity index 91%
rename from core-kotlin/kotlin-ktor/resources/logback.xml
rename to kotlin-libraries/resources/logback.xml
index 274cdcdb02..9452207268
--- a/core-kotlin/kotlin-ktor/resources/logback.xml
+++ b/kotlin-libraries/resources/logback.xml
@@ -1,11 +1,11 @@
-
-
-
- %d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
-
-
-
-
-
-
+
+
+
+ %d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
+
+
+
+
+
+
\ No newline at end of file
diff --git a/core-kotlin/kotlin-ktor/settings.gradle b/kotlin-libraries/settings.gradle
old mode 100755
new mode 100644
similarity index 94%
rename from core-kotlin/kotlin-ktor/settings.gradle
rename to kotlin-libraries/settings.gradle
index 13bbce9583..c91c993971
--- a/core-kotlin/kotlin-ktor/settings.gradle
+++ b/kotlin-libraries/settings.gradle
@@ -1,2 +1,2 @@
-rootProject.name = 'KtorWithKotlin'
-
+rootProject.name = 'KtorWithKotlin'
+
diff --git a/core-kotlin/src/main/kotlin/com/baeldung/klaxon/CustomProduct.kt b/kotlin-libraries/src/main/kotlin/com/baeldung/klaxon/CustomProduct.kt
similarity index 100%
rename from core-kotlin/src/main/kotlin/com/baeldung/klaxon/CustomProduct.kt
rename to kotlin-libraries/src/main/kotlin/com/baeldung/klaxon/CustomProduct.kt
diff --git a/core-kotlin/src/main/kotlin/com/baeldung/klaxon/Product.kt b/kotlin-libraries/src/main/kotlin/com/baeldung/klaxon/Product.kt
similarity index 100%
rename from core-kotlin/src/main/kotlin/com/baeldung/klaxon/Product.kt
rename to kotlin-libraries/src/main/kotlin/com/baeldung/klaxon/Product.kt
diff --git a/core-kotlin/src/main/kotlin/com/baeldung/klaxon/ProductData.kt b/kotlin-libraries/src/main/kotlin/com/baeldung/klaxon/ProductData.kt
similarity index 100%
rename from core-kotlin/src/main/kotlin/com/baeldung/klaxon/ProductData.kt
rename to kotlin-libraries/src/main/kotlin/com/baeldung/klaxon/ProductData.kt
diff --git a/core-kotlin/src/main/kotlin/com/baeldung/kotlin/kodein/Controller.kt b/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/kodein/Controller.kt
similarity index 100%
rename from core-kotlin/src/main/kotlin/com/baeldung/kotlin/kodein/Controller.kt
rename to kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/kodein/Controller.kt
diff --git a/core-kotlin/src/main/kotlin/com/baeldung/kotlin/kodein/Dao.kt b/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/kodein/Dao.kt
similarity index 100%
rename from core-kotlin/src/main/kotlin/com/baeldung/kotlin/kodein/Dao.kt
rename to kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/kodein/Dao.kt
diff --git a/core-kotlin/src/main/kotlin/com/baeldung/kotlin/kodein/JdbcDao.kt b/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/kodein/JdbcDao.kt
similarity index 100%
rename from core-kotlin/src/main/kotlin/com/baeldung/kotlin/kodein/JdbcDao.kt
rename to kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/kodein/JdbcDao.kt
diff --git a/core-kotlin/src/main/kotlin/com/baeldung/kotlin/kodein/MongoDao.kt b/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/kodein/MongoDao.kt
similarity index 100%
rename from core-kotlin/src/main/kotlin/com/baeldung/kotlin/kodein/MongoDao.kt
rename to kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/kodein/MongoDao.kt
diff --git a/core-kotlin/src/main/kotlin/com/baeldung/kotlin/kodein/Service.kt b/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/kodein/Service.kt
similarity index 100%
rename from core-kotlin/src/main/kotlin/com/baeldung/kotlin/kodein/Service.kt
rename to kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/kodein/Service.kt
diff --git a/core-kotlin/src/main/kotlin/com/baeldung/kotlin/mockito/BookService.kt b/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/mockito/BookService.kt
similarity index 100%
rename from core-kotlin/src/main/kotlin/com/baeldung/kotlin/mockito/BookService.kt
rename to kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/mockito/BookService.kt
diff --git a/core-kotlin/src/main/kotlin/com/baeldung/kotlin/mockito/LendBookManager.kt b/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/mockito/LendBookManager.kt
similarity index 100%
rename from core-kotlin/src/main/kotlin/com/baeldung/kotlin/mockito/LendBookManager.kt
rename to kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/mockito/LendBookManager.kt
diff --git a/core-kotlin/kotlin-ktor/src/main/kotlin/APIServer.kt b/kotlin-libraries/src/main/kotlin/com/baeldung/ktor/APIServer.kt
similarity index 100%
rename from core-kotlin/kotlin-ktor/src/main/kotlin/APIServer.kt
rename to kotlin-libraries/src/main/kotlin/com/baeldung/ktor/APIServer.kt
diff --git a/core-kotlin/src/test/kotlin/com/baeldung/klaxon/KlaxonUnitTest.kt b/kotlin-libraries/src/test/kotlin/com/baeldung/klaxon/KlaxonUnitTest.kt
similarity index 100%
rename from core-kotlin/src/test/kotlin/com/baeldung/klaxon/KlaxonUnitTest.kt
rename to kotlin-libraries/src/test/kotlin/com/baeldung/klaxon/KlaxonUnitTest.kt
diff --git a/core-kotlin/src/test/kotlin/com/baeldung/kotlin/exposed/ExposedTest.kt b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/exposed/ExposedTest.kt
similarity index 100%
rename from core-kotlin/src/test/kotlin/com/baeldung/kotlin/exposed/ExposedTest.kt
rename to kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/exposed/ExposedTest.kt
diff --git a/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/junit5/Calculator.kt b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/junit5/Calculator.kt
new file mode 100644
index 0000000000..1b61c05887
--- /dev/null
+++ b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/junit5/Calculator.kt
@@ -0,0 +1,17 @@
+package com.baeldung.kotlin.junit5
+
+class Calculator {
+ fun add(a: Int, b: Int) = a + b
+
+ fun divide(a: Int, b: Int) = if (b == 0) {
+ throw DivideByZeroException(a)
+ } else {
+ a / b
+ }
+
+ fun square(a: Int) = a * a
+
+ fun squareRoot(a: Int) = Math.sqrt(a.toDouble())
+
+ fun log(base: Int, value: Int) = Math.log(value.toDouble()) / Math.log(base.toDouble())
+}
diff --git a/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/junit5/DivideByZeroException.kt b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/junit5/DivideByZeroException.kt
new file mode 100644
index 0000000000..60bc4e2944
--- /dev/null
+++ b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/junit5/DivideByZeroException.kt
@@ -0,0 +1,3 @@
+package com.baeldung.kotlin.junit5
+
+class DivideByZeroException(val numerator: Int) : Exception()
diff --git a/core-kotlin/src/test/kotlin/com/baeldung/kotlin/khttp/KhttpLiveTest.kt b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/khttp/KhttpLiveTest.kt
similarity index 100%
rename from core-kotlin/src/test/kotlin/com/baeldung/kotlin/khttp/KhttpLiveTest.kt
rename to kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/khttp/KhttpLiveTest.kt
diff --git a/core-kotlin/src/test/kotlin/com/baeldung/kotlin/kodein/KodeinUnitTest.kt b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/kodein/KodeinUnitTest.kt
similarity index 100%
rename from core-kotlin/src/test/kotlin/com/baeldung/kotlin/kodein/KodeinUnitTest.kt
rename to kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/kodein/KodeinUnitTest.kt
diff --git a/core-kotlin/src/test/kotlin/com/baeldung/kotlin/mockito/LendBookManagerTest.kt b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/mockito/LendBookManagerTest.kt
similarity index 100%
rename from core-kotlin/src/test/kotlin/com/baeldung/kotlin/mockito/LendBookManagerTest.kt
rename to kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/mockito/LendBookManagerTest.kt
diff --git a/core-kotlin/src/test/kotlin/com/baeldung/kotlin/mockito/LendBookManagerTestMockitoKotlin.kt b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/mockito/LendBookManagerTestMockitoKotlin.kt
similarity index 100%
rename from core-kotlin/src/test/kotlin/com/baeldung/kotlin/mockito/LendBookManagerTestMockitoKotlin.kt
rename to kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/mockito/LendBookManagerTestMockitoKotlin.kt
diff --git a/core-kotlin/src/test/kotlin/com/baeldung/kotlin/spek/CalculatorSubjectTest5.kt b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/spek/CalculatorSubjectTest5.kt
similarity index 100%
rename from core-kotlin/src/test/kotlin/com/baeldung/kotlin/spek/CalculatorSubjectTest5.kt
rename to kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/spek/CalculatorSubjectTest5.kt
diff --git a/core-kotlin/src/test/kotlin/com/baeldung/kotlin/spek/CalculatorTest5.kt b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/spek/CalculatorTest5.kt
similarity index 100%
rename from core-kotlin/src/test/kotlin/com/baeldung/kotlin/spek/CalculatorTest5.kt
rename to kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/spek/CalculatorTest5.kt
diff --git a/core-kotlin/src/test/kotlin/com/baeldung/kotlin/spek/DataDrivenTest5.kt b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/spek/DataDrivenTest5.kt
similarity index 100%
rename from core-kotlin/src/test/kotlin/com/baeldung/kotlin/spek/DataDrivenTest5.kt
rename to kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/spek/DataDrivenTest5.kt
diff --git a/core-kotlin/src/test/kotlin/com/baeldung/kotlin/spek/GroupTest5.kt b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/spek/GroupTest5.kt
similarity index 100%
rename from core-kotlin/src/test/kotlin/com/baeldung/kotlin/spek/GroupTest5.kt
rename to kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/spek/GroupTest5.kt
diff --git a/libraries/pom.xml b/libraries/pom.xml
index 4768268f59..1a88acfb7b 100644
--- a/libraries/pom.xml
+++ b/libraries/pom.xml
@@ -777,19 +777,6 @@
-
- org.apache.maven.plugins
- maven-dependency-plugin
-
-
- org.apache.felix
- maven-bundle-plugin
- ${maven-bundle-plugin.version}
- maven-plugin
-
-
- true
-
maven-failsafe-plugin
${maven-failsafe-plugin.version}
diff --git a/lombok/src/main/java/com/baeldung/lombok/builder/Child.java b/lombok/src/main/java/com/baeldung/lombok/builder/Child.java
new file mode 100644
index 0000000000..70f6d9c46e
--- /dev/null
+++ b/lombok/src/main/java/com/baeldung/lombok/builder/Child.java
@@ -0,0 +1,19 @@
+package com.baeldung.lombok.builder;
+
+import lombok.Builder;
+import lombok.Getter;
+
+@Getter
+public class Child extends Parent {
+
+ private final String childName;
+ private final int childAge;
+
+ @Builder(builderMethodName = "childBuilder")
+ public Child(String parentName, int parentAge, String childName, int childAge) {
+ super(parentName, parentAge);
+ this.childName = childName;
+ this.childAge = childAge;
+ }
+
+}
diff --git a/lombok/src/main/java/com/baeldung/lombok/builder/Parent.java b/lombok/src/main/java/com/baeldung/lombok/builder/Parent.java
new file mode 100644
index 0000000000..0cf76d4b00
--- /dev/null
+++ b/lombok/src/main/java/com/baeldung/lombok/builder/Parent.java
@@ -0,0 +1,11 @@
+package com.baeldung.lombok.builder;
+
+import lombok.Builder;
+import lombok.Getter;
+
+@Getter
+@Builder
+public class Parent {
+ private final String parentName;
+ private final int parentAge;
+}
\ No newline at end of file
diff --git a/lombok/src/main/java/com/baeldung/lombok/getter/GetterBoolean.java b/lombok/src/main/java/com/baeldung/lombok/getter/GetterBoolean.java
new file mode 100644
index 0000000000..2191396e5d
--- /dev/null
+++ b/lombok/src/main/java/com/baeldung/lombok/getter/GetterBoolean.java
@@ -0,0 +1,15 @@
+package com.baeldung.lombok.getter;
+
+
+import lombok.Getter;
+
+/**
+ * Related Article Sections:
+ * 4. Using @Getter on a Boolean Field
+ *
+ */
+public class GetterBoolean {
+
+ @Getter
+ private Boolean running = true;
+}
diff --git a/lombok/src/main/java/com/baeldung/lombok/getter/GetterBooleanPrimitive.java b/lombok/src/main/java/com/baeldung/lombok/getter/GetterBooleanPrimitive.java
new file mode 100644
index 0000000000..5601f85b8b
--- /dev/null
+++ b/lombok/src/main/java/com/baeldung/lombok/getter/GetterBooleanPrimitive.java
@@ -0,0 +1,16 @@
+package com.baeldung.lombok.getter;
+
+
+import lombok.Getter;
+
+/**
+ * Related Article Sections:
+ * 3. Using @Getter on a boolean Field
+ *
+ */
+public class GetterBooleanPrimitive {
+
+ @Getter
+ private boolean running;
+
+}
diff --git a/lombok/src/main/java/com/baeldung/lombok/getter/GetterBooleanPrimitiveSameAccessor.java b/lombok/src/main/java/com/baeldung/lombok/getter/GetterBooleanPrimitiveSameAccessor.java
new file mode 100644
index 0000000000..af29a33c20
--- /dev/null
+++ b/lombok/src/main/java/com/baeldung/lombok/getter/GetterBooleanPrimitiveSameAccessor.java
@@ -0,0 +1,18 @@
+package com.baeldung.lombok.getter;
+
+
+import lombok.Getter;
+
+/**
+ * Related Article Sections:
+ * 3.2. Two boolean Fields With the Same Accessor Name
+ *
+ */
+public class GetterBooleanPrimitiveSameAccessor {
+
+ @Getter
+ boolean running = true;
+
+ @Getter
+ boolean isRunning = false;
+}
diff --git a/lombok/src/main/java/com/baeldung/lombok/getter/GetterBooleanSameAccessor.java b/lombok/src/main/java/com/baeldung/lombok/getter/GetterBooleanSameAccessor.java
new file mode 100644
index 0000000000..d972273b71
--- /dev/null
+++ b/lombok/src/main/java/com/baeldung/lombok/getter/GetterBooleanSameAccessor.java
@@ -0,0 +1,13 @@
+package com.baeldung.lombok.getter;
+
+import lombok.Getter;
+
+/**
+ * Related Article Sections:
+ * 3.1. A boolean Field Having the Same Name With Its Accessor
+ *
+ */
+public class GetterBooleanSameAccessor {
+ @Getter
+ private boolean isRunning = true;
+}
diff --git a/lombok/src/main/java/com/baeldung/lombok/getter/GetterBooleanType.java b/lombok/src/main/java/com/baeldung/lombok/getter/GetterBooleanType.java
new file mode 100644
index 0000000000..0d3b9a928a
--- /dev/null
+++ b/lombok/src/main/java/com/baeldung/lombok/getter/GetterBooleanType.java
@@ -0,0 +1,15 @@
+package com.baeldung.lombok.getter;
+
+
+import lombok.Getter;
+
+/**
+ * Related Article Sections:
+ * 4. Using @Getter on a Boolean Field
+ *
+ */
+public class GetterBooleanType {
+
+ @Getter
+ private Boolean running = true;
+}
diff --git a/lombok/src/test/java/com/baeldung/lombok/builder/BuilderUnitTest.java b/lombok/src/test/java/com/baeldung/lombok/builder/BuilderUnitTest.java
index acad7d6c04..56a380569d 100644
--- a/lombok/src/test/java/com/baeldung/lombok/builder/BuilderUnitTest.java
+++ b/lombok/src/test/java/com/baeldung/lombok/builder/BuilderUnitTest.java
@@ -1,42 +1,59 @@
package com.baeldung.lombok.builder;
+import static org.assertj.core.api.Assertions.assertThat;
+
import org.junit.jupiter.api.Test;
-import static org.assertj.core.api.Assertions.*;
-
-public class BuilderUnitTest
-{
+public class BuilderUnitTest {
@Test
public void givenBuilder_WidgetIsBuilt() {
- Widget testWidget = Widget.builder().name("foo").id(1).build();
- assertThat(testWidget.getName())
- .isEqualTo("foo");
- assertThat(testWidget.getId())
- .isEqualTo(1);
+ Widget testWidget = Widget.builder()
+ .name("foo")
+ .id(1)
+ .build();
+ assertThat(testWidget.getName()).isEqualTo("foo");
+ assertThat(testWidget.getId()).isEqualTo(1);
}
@Test
public void givenToBuilder_whenToBuilder_BuilderIsCreated() {
- Widget testWidget = Widget.builder().name("foo").id(1).build();
+ Widget testWidget = Widget.builder()
+ .name("foo")
+ .id(1)
+ .build();
Widget.WidgetBuilder widgetBuilder = testWidget.toBuilder();
- Widget newWidget = widgetBuilder.id(2).build();
- assertThat(newWidget.getName())
- .isEqualTo("foo");
- assertThat(newWidget.getId())
- .isEqualTo(2);
+ Widget newWidget = widgetBuilder.id(2)
+ .build();
+ assertThat(newWidget.getName()).isEqualTo("foo");
+ assertThat(newWidget.getId()).isEqualTo(2);
}
-
-
@Test
public void givenBuilderMethod_ClientIsBuilt() {
- ImmutableClient testImmutableClient = ClientBuilder.builder().name("foo").id(1).build();
- assertThat(testImmutableClient.getName())
- .isEqualTo("foo");
- assertThat(testImmutableClient.getId())
- .isEqualTo(1);
+ ImmutableClient testImmutableClient = ClientBuilder.builder()
+ .name("foo")
+ .id(1)
+ .build();
+ assertThat(testImmutableClient.getName()).isEqualTo("foo");
+ assertThat(testImmutableClient.getId()).isEqualTo(1);
}
+
+ @Test
+ public void givenBuilderAtMethodLevel_ChildInheritingParentIsBuilt() {
+ Child child = Child.childBuilder()
+ .parentName("Andrea")
+ .parentAge(38)
+ .childName("Emma")
+ .childAge(6)
+ .build();
+
+ assertThat(child.getChildName()).isEqualTo("Emma");
+ assertThat(child.getChildAge()).isEqualTo(6);
+ assertThat(child.getParentName()).isEqualTo("Andrea");
+ assertThat(child.getParentAge()).isEqualTo(38);
+ }
+
}
diff --git a/lombok/src/test/java/com/baeldung/lombok/getter/GetterBooleanUnitTest.java b/lombok/src/test/java/com/baeldung/lombok/getter/GetterBooleanUnitTest.java
new file mode 100644
index 0000000000..632594d575
--- /dev/null
+++ b/lombok/src/test/java/com/baeldung/lombok/getter/GetterBooleanUnitTest.java
@@ -0,0 +1,34 @@
+package com.baeldung.lombok.getter;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+public class GetterBooleanUnitTest {
+
+ @Test
+ public void whenBasicBooleanField_thenMethodNamePrefixedWithIsFollowedByFieldName() {
+ GetterBooleanPrimitive lombokExamples = new GetterBooleanPrimitive();
+ assertFalse(lombokExamples.isRunning());
+ }
+
+ @Test
+ public void whenBooleanFieldPrefixedWithIs_thenMethodNameIsSameAsFieldName() {
+ GetterBooleanSameAccessor lombokExamples = new GetterBooleanSameAccessor();
+ assertTrue(lombokExamples.isRunning());
+ }
+
+ @Test
+ public void whenTwoBooleanFieldsCauseNamingConflict_thenLombokMapsToFirstDeclaredField() {
+ GetterBooleanPrimitiveSameAccessor lombokExamples = new GetterBooleanPrimitiveSameAccessor();
+ assertTrue(lombokExamples.isRunning() == lombokExamples.running);
+ assertFalse(lombokExamples.isRunning() == lombokExamples.isRunning);
+ }
+
+ @Test
+ public void whenFieldOfBooleanType_thenLombokPrefixesMethodWithGetInsteadOfIs() {
+ GetterBooleanType lombokExamples = new GetterBooleanType();
+ assertTrue(lombokExamples.getRunning());
+ }
+}
diff --git a/persistence-modules/spring-data-dynamodb/pom.xml b/persistence-modules/spring-data-dynamodb/pom.xml
index f3d794d001..4cb805131a 100644
--- a/persistence-modules/spring-data-dynamodb/pom.xml
+++ b/persistence-modules/spring-data-dynamodb/pom.xml
@@ -154,25 +154,6 @@
org.apache.maven.plugins
maven-war-plugin
-
- org.apache.maven.plugins
- maven-dependency-plugin
- ${maven-dependency-plugin.version}
-
-
- copy-dependencies
- test-compile
-
- copy-dependencies
-
-
- test
- so,dll,dylib
- ${project.basedir}/native-libs
-
-
-
-
@@ -196,7 +177,6 @@
1.11.106
1.11.86
https://s3-us-west-2.amazonaws.com/dynamodb-local/release
- 2.10
diff --git a/pom.xml b/pom.xml
index 4f7fa39a67..7a7e2d7f64 100644
--- a/pom.xml
+++ b/pom.xml
@@ -352,6 +352,7 @@
java-streams
core-java-persistence
core-kotlin
+ kotlin-libraries
core-groovy
core-java-concurrency
core-java-concurrency-collections
@@ -1240,6 +1241,7 @@
spring-boot-ops
spring-5
core-kotlin
+ kotlin-libraries
core-java
google-web-toolkit
spring-security-mvc-custom
diff --git a/spring-boot-logging-log4j2/README.md b/spring-boot-logging-log4j2/README.md
index 7676bd1919..305957ed8d 100644
--- a/spring-boot-logging-log4j2/README.md
+++ b/spring-boot-logging-log4j2/README.md
@@ -1,2 +1,3 @@
### Relevant Articles:
- [Logging in Spring Boot](http://www.baeldung.com/spring-boot-logging)
+- [How to Disable Console Logging in Spring Boot](https://www.baeldung.com/spring-boot-disable-console-logging)
diff --git a/spring-boot-mvc/README.md b/spring-boot-mvc/README.md
index a22a6df667..b46dbe3bae 100644
--- a/spring-boot-mvc/README.md
+++ b/spring-boot-mvc/README.md
@@ -2,3 +2,9 @@
- [Guide to the Favicon in Spring Boot](http://www.baeldung.com/spring-boot-favicon)
- [Custom Validation MessageSource in Spring Boot](https://www.baeldung.com/spring-custom-validation-message-source)
+- [Spring Boot Annotations](http://www.baeldung.com/spring-boot-annotations)
+- [Spring Scheduling Annotations](http://www.baeldung.com/spring-scheduling-annotations)
+- [Spring Web Annotations](http://www.baeldung.com/spring-mvc-annotations)
+- [Spring Core Annotations](http://www.baeldung.com/spring-core-annotations)
+- [Display RSS Feed with Spring MVC](http://www.baeldung.com/spring-mvc-rss-feed)
+
diff --git a/spring-boot-mvc/pom.xml b/spring-boot-mvc/pom.xml
index d0fce26bb5..e456155f36 100644
--- a/spring-boot-mvc/pom.xml
+++ b/spring-boot-mvc/pom.xml
@@ -32,6 +32,13 @@
org.springframework.boot
spring-boot-starter-validation
+
+
+
+ com.rometools
+ rome
+ ${rome.version}
+
@@ -47,6 +54,8 @@
UTF-8
UTF-8
1.8
+
+ 1.10.0
diff --git a/spring-mvc-java/src/main/java/com/baeldung/annotations/Bike.java b/spring-boot-mvc/src/main/java/com/baeldung/annotations/Bike.java
similarity index 100%
rename from spring-mvc-java/src/main/java/com/baeldung/annotations/Bike.java
rename to spring-boot-mvc/src/main/java/com/baeldung/annotations/Bike.java
diff --git a/spring-mvc-java/src/main/java/com/baeldung/annotations/Biker.java b/spring-boot-mvc/src/main/java/com/baeldung/annotations/Biker.java
similarity index 100%
rename from spring-mvc-java/src/main/java/com/baeldung/annotations/Biker.java
rename to spring-boot-mvc/src/main/java/com/baeldung/annotations/Biker.java
diff --git a/spring-mvc-java/src/main/java/com/baeldung/annotations/Car.java b/spring-boot-mvc/src/main/java/com/baeldung/annotations/Car.java
similarity index 100%
rename from spring-mvc-java/src/main/java/com/baeldung/annotations/Car.java
rename to spring-boot-mvc/src/main/java/com/baeldung/annotations/Car.java
diff --git a/spring-mvc-java/src/main/java/com/baeldung/annotations/CarMechanic.java b/spring-boot-mvc/src/main/java/com/baeldung/annotations/CarMechanic.java
similarity index 100%
rename from spring-mvc-java/src/main/java/com/baeldung/annotations/CarMechanic.java
rename to spring-boot-mvc/src/main/java/com/baeldung/annotations/CarMechanic.java
diff --git a/spring-mvc-java/src/main/java/com/baeldung/annotations/CarUtility.java b/spring-boot-mvc/src/main/java/com/baeldung/annotations/CarUtility.java
similarity index 100%
rename from spring-mvc-java/src/main/java/com/baeldung/annotations/CarUtility.java
rename to spring-boot-mvc/src/main/java/com/baeldung/annotations/CarUtility.java
diff --git a/spring-mvc-java/src/main/java/com/baeldung/annotations/CustomException.java b/spring-boot-mvc/src/main/java/com/baeldung/annotations/CustomException.java
similarity index 100%
rename from spring-mvc-java/src/main/java/com/baeldung/annotations/CustomException.java
rename to spring-boot-mvc/src/main/java/com/baeldung/annotations/CustomException.java
diff --git a/spring-mvc-java/src/main/java/com/baeldung/annotations/CustomResponseController.java b/spring-boot-mvc/src/main/java/com/baeldung/annotations/CustomResponseController.java
similarity index 100%
rename from spring-mvc-java/src/main/java/com/baeldung/annotations/CustomResponseController.java
rename to spring-boot-mvc/src/main/java/com/baeldung/annotations/CustomResponseController.java
diff --git a/spring-mvc-java/src/main/java/com/baeldung/annotations/CustomResponseWithBuilderController.java b/spring-boot-mvc/src/main/java/com/baeldung/annotations/CustomResponseWithBuilderController.java
similarity index 100%
rename from spring-mvc-java/src/main/java/com/baeldung/annotations/CustomResponseWithBuilderController.java
rename to spring-boot-mvc/src/main/java/com/baeldung/annotations/CustomResponseWithBuilderController.java
diff --git a/spring-mvc-java/src/main/java/com/baeldung/annotations/Driver.java b/spring-boot-mvc/src/main/java/com/baeldung/annotations/Driver.java
similarity index 100%
rename from spring-mvc-java/src/main/java/com/baeldung/annotations/Driver.java
rename to spring-boot-mvc/src/main/java/com/baeldung/annotations/Driver.java
diff --git a/spring-mvc-java/src/main/java/com/baeldung/annotations/Engine.java b/spring-boot-mvc/src/main/java/com/baeldung/annotations/Engine.java
similarity index 100%
rename from spring-mvc-java/src/main/java/com/baeldung/annotations/Engine.java
rename to spring-boot-mvc/src/main/java/com/baeldung/annotations/Engine.java
diff --git a/spring-mvc-java/src/main/java/com/baeldung/annotations/Vehicle.java b/spring-boot-mvc/src/main/java/com/baeldung/annotations/Vehicle.java
similarity index 100%
rename from spring-mvc-java/src/main/java/com/baeldung/annotations/Vehicle.java
rename to spring-boot-mvc/src/main/java/com/baeldung/annotations/Vehicle.java
diff --git a/spring-mvc-java/src/main/java/com/baeldung/annotations/VehicleController.java b/spring-boot-mvc/src/main/java/com/baeldung/annotations/VehicleController.java
similarity index 100%
rename from spring-mvc-java/src/main/java/com/baeldung/annotations/VehicleController.java
rename to spring-boot-mvc/src/main/java/com/baeldung/annotations/VehicleController.java
diff --git a/spring-mvc-java/src/main/java/com/baeldung/annotations/VehicleFactoryApplication.java b/spring-boot-mvc/src/main/java/com/baeldung/annotations/VehicleFactoryApplication.java
similarity index 100%
rename from spring-mvc-java/src/main/java/com/baeldung/annotations/VehicleFactoryApplication.java
rename to spring-boot-mvc/src/main/java/com/baeldung/annotations/VehicleFactoryApplication.java
diff --git a/spring-mvc-java/src/main/java/com/baeldung/annotations/VehicleFactoryConfig.java b/spring-boot-mvc/src/main/java/com/baeldung/annotations/VehicleFactoryConfig.java
similarity index 100%
rename from spring-mvc-java/src/main/java/com/baeldung/annotations/VehicleFactoryConfig.java
rename to spring-boot-mvc/src/main/java/com/baeldung/annotations/VehicleFactoryConfig.java
diff --git a/spring-mvc-java/src/main/java/com/baeldung/annotations/VehicleRepository.java b/spring-boot-mvc/src/main/java/com/baeldung/annotations/VehicleRepository.java
similarity index 100%
rename from spring-mvc-java/src/main/java/com/baeldung/annotations/VehicleRepository.java
rename to spring-boot-mvc/src/main/java/com/baeldung/annotations/VehicleRepository.java
diff --git a/spring-mvc-java/src/main/java/com/baeldung/annotations/VehicleRestController.java b/spring-boot-mvc/src/main/java/com/baeldung/annotations/VehicleRestController.java
similarity index 100%
rename from spring-mvc-java/src/main/java/com/baeldung/annotations/VehicleRestController.java
rename to spring-boot-mvc/src/main/java/com/baeldung/annotations/VehicleRestController.java
diff --git a/spring-mvc-java/src/main/java/com/baeldung/annotations/VehicleService.java b/spring-boot-mvc/src/main/java/com/baeldung/annotations/VehicleService.java
similarity index 100%
rename from spring-mvc-java/src/main/java/com/baeldung/annotations/VehicleService.java
rename to spring-boot-mvc/src/main/java/com/baeldung/annotations/VehicleService.java
diff --git a/spring-mvc-java/src/main/java/com/baeldung/rss/RssFeedApplication.java b/spring-boot-mvc/src/main/java/com/baeldung/rss/RssFeedApplication.java
similarity index 100%
rename from spring-mvc-java/src/main/java/com/baeldung/rss/RssFeedApplication.java
rename to spring-boot-mvc/src/main/java/com/baeldung/rss/RssFeedApplication.java
diff --git a/spring-mvc-java/src/main/java/com/baeldung/rss/RssFeedController.java b/spring-boot-mvc/src/main/java/com/baeldung/rss/RssFeedController.java
similarity index 100%
rename from spring-mvc-java/src/main/java/com/baeldung/rss/RssFeedController.java
rename to spring-boot-mvc/src/main/java/com/baeldung/rss/RssFeedController.java
diff --git a/spring-mvc-java/src/main/java/com/baeldung/rss/RssFeedView.java b/spring-boot-mvc/src/main/java/com/baeldung/rss/RssFeedView.java
similarity index 100%
rename from spring-mvc-java/src/main/java/com/baeldung/rss/RssFeedView.java
rename to spring-boot-mvc/src/main/java/com/baeldung/rss/RssFeedView.java
diff --git a/spring-mvc-java/src/test/java/com/baeldung/rss/RssFeedUnitTest.java b/spring-boot-mvc/src/test/java/com/baeldung/rss/RssFeedUnitTest.java
similarity index 100%
rename from spring-mvc-java/src/test/java/com/baeldung/rss/RssFeedUnitTest.java
rename to spring-boot-mvc/src/test/java/com/baeldung/rss/RssFeedUnitTest.java
diff --git a/spring-boot-persistence/README.MD b/spring-boot-persistence/README.MD
index 72fdca74fa..6cf172426a 100644
--- a/spring-boot-persistence/README.MD
+++ b/spring-boot-persistence/README.MD
@@ -3,3 +3,4 @@
- [Spring Boot with Multiple SQL Import Files](http://www.baeldung.com/spring-boot-sql-import-files)
- [Configuring Separate Spring DataSource for Tests](http://www.baeldung.com/spring-testing-separate-data-source)
- [Quick Guide on data.sql and schema.sql Files in Spring Boot](http://www.baeldung.com/spring-boot-data-sql-and-schema-sql)
+- [Configuring a Tomcat Connection Pool in Spring Boot](https://www.baeldung.com/spring-boot-tomcat-connection-pool)
diff --git a/spring-data-jpa/pom.xml b/spring-data-jpa/pom.xml
index c4893df759..8691ce1f09 100644
--- a/spring-data-jpa/pom.xml
+++ b/spring-data-jpa/pom.xml
@@ -41,6 +41,26 @@
guava
21.0
+
+
+
+ org.junit.jupiter
+ junit-jupiter-api
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ test
+
+
+
+
+ org.junit.platform
+ junit-platform-launcher
+ ${junit-platform.version}
+ test
+
\ No newline at end of file
diff --git a/spring-data-jpa/src/main/java/com/baeldung/Application.java b/spring-data-jpa/src/main/java/com/baeldung/Application.java
index 4e14f94311..72d29d9fa5 100644
--- a/spring-data-jpa/src/main/java/com/baeldung/Application.java
+++ b/spring-data-jpa/src/main/java/com/baeldung/Application.java
@@ -1,11 +1,11 @@
package com.baeldung;
-import com.baeldung.dao.repositories.impl.ExtendedRepositoryImpl;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
+import com.baeldung.dao.repositories.impl.ExtendedRepositoryImpl;
+
@SpringBootApplication
@EnableJpaRepositories(repositoryBaseClass = ExtendedRepositoryImpl.class)
public class Application {
diff --git a/spring-data-jpa/src/main/java/com/baeldung/ddd/event/Aggregate.java b/spring-data-jpa/src/main/java/com/baeldung/ddd/event/Aggregate.java
new file mode 100644
index 0000000000..bf6ff0a0b9
--- /dev/null
+++ b/spring-data-jpa/src/main/java/com/baeldung/ddd/event/Aggregate.java
@@ -0,0 +1,46 @@
+/**
+ *
+ */
+package com.baeldung.ddd.event;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Transient;
+
+import org.springframework.context.ApplicationEventPublisher;
+
+@Entity
+class Aggregate {
+ @Transient
+ private ApplicationEventPublisher eventPublisher;
+ @Id
+ private long id;
+
+ private Aggregate() {
+ }
+
+ Aggregate(long id, ApplicationEventPublisher eventPublisher) {
+ this.id = id;
+ this.eventPublisher = eventPublisher;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return "DomainEntity [id=" + id + "]";
+ }
+
+ void domainOperation() {
+ // some business logic
+ if (eventPublisher != null) {
+ eventPublisher.publishEvent(new DomainEvent());
+ }
+ }
+
+ long getId() {
+ return id;
+ }
+
+}
diff --git a/spring-data-jpa/src/main/java/com/baeldung/ddd/event/Aggregate2.java b/spring-data-jpa/src/main/java/com/baeldung/ddd/event/Aggregate2.java
new file mode 100644
index 0000000000..3d2816299a
--- /dev/null
+++ b/spring-data-jpa/src/main/java/com/baeldung/ddd/event/Aggregate2.java
@@ -0,0 +1,44 @@
+/**
+ *
+ */
+package com.baeldung.ddd.event;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Transient;
+
+import org.springframework.data.domain.AfterDomainEventPublication;
+import org.springframework.data.domain.DomainEvents;
+
+@Entity
+public class Aggregate2 {
+ @Transient
+ private final Collection domainEvents;
+ @Id
+ @GeneratedValue
+ private long id;
+
+ public Aggregate2() {
+ domainEvents = new ArrayList<>();
+ }
+
+ @AfterDomainEventPublication
+ public void clearEvents() {
+ domainEvents.clear();
+ }
+
+ public void domainOperation() {
+ // some domain operation
+ domainEvents.add(new DomainEvent());
+ }
+
+ @DomainEvents
+ public Collection events() {
+ return domainEvents;
+ }
+
+}
diff --git a/spring-data-jpa/src/main/java/com/baeldung/ddd/event/Aggregate2Repository.java b/spring-data-jpa/src/main/java/com/baeldung/ddd/event/Aggregate2Repository.java
new file mode 100644
index 0000000000..2a95abe347
--- /dev/null
+++ b/spring-data-jpa/src/main/java/com/baeldung/ddd/event/Aggregate2Repository.java
@@ -0,0 +1,10 @@
+/**
+ *
+ */
+package com.baeldung.ddd.event;
+
+import org.springframework.data.repository.CrudRepository;
+
+public interface Aggregate2Repository extends CrudRepository {
+
+}
diff --git a/spring-data-jpa/src/main/java/com/baeldung/ddd/event/Aggregate3.java b/spring-data-jpa/src/main/java/com/baeldung/ddd/event/Aggregate3.java
new file mode 100644
index 0000000000..e0c3131b06
--- /dev/null
+++ b/spring-data-jpa/src/main/java/com/baeldung/ddd/event/Aggregate3.java
@@ -0,0 +1,23 @@
+/**
+ *
+ */
+package com.baeldung.ddd.event;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+import org.springframework.data.domain.AbstractAggregateRoot;
+
+@Entity
+public class Aggregate3 extends AbstractAggregateRoot {
+ @Id
+ @GeneratedValue
+ private long id;
+
+ public void domainOperation() {
+ // some domain operation
+ registerEvent(new DomainEvent());
+ }
+
+}
diff --git a/spring-data-jpa/src/main/java/com/baeldung/ddd/event/Aggregate3Repository.java b/spring-data-jpa/src/main/java/com/baeldung/ddd/event/Aggregate3Repository.java
new file mode 100644
index 0000000000..e442bdb210
--- /dev/null
+++ b/spring-data-jpa/src/main/java/com/baeldung/ddd/event/Aggregate3Repository.java
@@ -0,0 +1,14 @@
+/**
+ *
+ */
+package com.baeldung.ddd.event;
+
+import org.springframework.data.repository.CrudRepository;
+
+/**
+ * @author goobar
+ *
+ */
+public interface Aggregate3Repository extends CrudRepository {
+
+}
diff --git a/spring-data-jpa/src/main/java/com/baeldung/ddd/event/AggregateRepository.java b/spring-data-jpa/src/main/java/com/baeldung/ddd/event/AggregateRepository.java
new file mode 100644
index 0000000000..5a15156d03
--- /dev/null
+++ b/spring-data-jpa/src/main/java/com/baeldung/ddd/event/AggregateRepository.java
@@ -0,0 +1,10 @@
+/**
+ *
+ */
+package com.baeldung.ddd.event;
+
+import org.springframework.data.repository.CrudRepository;
+
+public interface AggregateRepository extends CrudRepository {
+
+}
diff --git a/spring-data-jpa/src/main/java/com/baeldung/ddd/event/DddConfig.java b/spring-data-jpa/src/main/java/com/baeldung/ddd/event/DddConfig.java
new file mode 100644
index 0000000000..1315b11875
--- /dev/null
+++ b/spring-data-jpa/src/main/java/com/baeldung/ddd/event/DddConfig.java
@@ -0,0 +1,15 @@
+/**
+ *
+ */
+package com.baeldung.ddd.event;
+
+import org.springframework.boot.SpringBootConfiguration;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.context.annotation.PropertySource;
+
+@SpringBootConfiguration
+@EnableAutoConfiguration
+@PropertySource("classpath:/ddd.properties")
+public class DddConfig {
+
+}
diff --git a/spring-data-jpa/src/main/java/com/baeldung/ddd/event/DomainEvent.java b/spring-data-jpa/src/main/java/com/baeldung/ddd/event/DomainEvent.java
new file mode 100644
index 0000000000..1e6479d4fc
--- /dev/null
+++ b/spring-data-jpa/src/main/java/com/baeldung/ddd/event/DomainEvent.java
@@ -0,0 +1,8 @@
+/**
+ *
+ */
+package com.baeldung.ddd.event;
+
+class DomainEvent {
+
+}
diff --git a/spring-data-jpa/src/main/java/com/baeldung/ddd/event/DomainService.java b/spring-data-jpa/src/main/java/com/baeldung/ddd/event/DomainService.java
new file mode 100644
index 0000000000..082c9bd88e
--- /dev/null
+++ b/spring-data-jpa/src/main/java/com/baeldung/ddd/event/DomainService.java
@@ -0,0 +1,31 @@
+/**
+ *
+ */
+package com.baeldung.ddd.event;
+
+import javax.transaction.Transactional;
+
+import org.springframework.context.ApplicationEventPublisher;
+import org.springframework.stereotype.Service;
+
+@Service
+public class DomainService {
+ private final ApplicationEventPublisher eventPublisher;
+ private final AggregateRepository repository;
+
+ public DomainService(AggregateRepository repository, ApplicationEventPublisher eventPublisher) {
+ this.repository = repository;
+ this.eventPublisher = eventPublisher;
+ }
+
+ @Transactional
+ public void serviceDomainOperation(long entityId) {
+ repository.findById(entityId)
+ .ifPresent(entity -> {
+ entity.domainOperation();
+ repository.save(entity);
+ eventPublisher.publishEvent(new DomainEvent());
+ });
+ }
+
+}
diff --git a/spring-data-jpa/src/main/resources/ddd.properties b/spring-data-jpa/src/main/resources/ddd.properties
new file mode 100644
index 0000000000..e5126b694b
--- /dev/null
+++ b/spring-data-jpa/src/main/resources/ddd.properties
@@ -0,0 +1 @@
+spring.datasource.initialization-mode=never
\ No newline at end of file
diff --git a/spring-data-jpa/src/main/resources/persistence-multiple-db.properties b/spring-data-jpa/src/main/resources/persistence-multiple-db.properties
index 53c6cecf8b..75534e8a54 100644
--- a/spring-data-jpa/src/main/resources/persistence-multiple-db.properties
+++ b/spring-data-jpa/src/main/resources/persistence-multiple-db.properties
@@ -3,7 +3,7 @@ jdbc.driverClassName=org.h2.Driver
user.jdbc.url=jdbc:h2:mem:spring_jpa_user;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS USERS
product.jdbc.url=jdbc:h2:mem:spring_jpa_product;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS PRODUCTS
jdbc.user=sa
-jdbc.pass=
+jdbc.pass=sa
# hibernate.X
hibernate.dialect=org.hibernate.dialect.H2Dialect
diff --git a/spring-data-jpa/src/main/resources/persistence.properties b/spring-data-jpa/src/main/resources/persistence.properties
index 5e83653401..3543e1b52b 100644
--- a/spring-data-jpa/src/main/resources/persistence.properties
+++ b/spring-data-jpa/src/main/resources/persistence.properties
@@ -2,7 +2,7 @@
jdbc.driverClassName=org.h2.Driver
jdbc.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS USERS
jdbc.user=sa
-jdbc.pass=
+jdbc.pass=sa
# hibernate.X
hibernate.dialect=org.hibernate.dialect.H2Dialect
diff --git a/spring-data-jpa/src/test/java/com/baeldung/dao/repositories/JpaRepositoriesIntegrationTest.java b/spring-data-jpa/src/test/java/com/baeldung/dao/repositories/JpaRepositoriesIntegrationTest.java
index eaadb9e44a..01405c0b8a 100644
--- a/spring-data-jpa/src/test/java/com/baeldung/dao/repositories/JpaRepositoriesIntegrationTest.java
+++ b/spring-data-jpa/src/test/java/com/baeldung/dao/repositories/JpaRepositoriesIntegrationTest.java
@@ -9,28 +9,22 @@ import static junit.framework.TestCase.assertTrue;
import java.util.List;
import java.util.Optional;
-import com.baeldung.config.PersistenceConfiguration;
-import com.baeldung.config.PersistenceProductConfiguration;
-import com.baeldung.config.PersistenceUserConfiguration;
-import com.baeldung.dao.repositories.ItemTypeRepository;
-import com.baeldung.dao.repositories.LocationRepository;
-import com.baeldung.dao.repositories.ReadOnlyLocationRepository;
-import com.baeldung.dao.repositories.StoreRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
+import com.baeldung.config.PersistenceConfiguration;
+import com.baeldung.config.PersistenceProductConfiguration;
+import com.baeldung.config.PersistenceUserConfiguration;
import com.baeldung.domain.Item;
import com.baeldung.domain.ItemType;
import com.baeldung.domain.Location;
import com.baeldung.domain.Store;
@RunWith(SpringRunner.class)
-@DataJpaTest(excludeAutoConfiguration = {PersistenceConfiguration.class, PersistenceUserConfiguration.class, PersistenceProductConfiguration.class})
+@DataJpaTest(excludeAutoConfiguration = { PersistenceConfiguration.class, PersistenceUserConfiguration.class, PersistenceProductConfiguration.class })
public class JpaRepositoriesIntegrationTest {
@Autowired
private LocationRepository locationRepository;
diff --git a/spring-data-jpa/src/test/java/com/baeldung/ddd/event/Aggregate2EventsIntegrationTest.java b/spring-data-jpa/src/test/java/com/baeldung/ddd/event/Aggregate2EventsIntegrationTest.java
new file mode 100644
index 0000000000..3f650d4d63
--- /dev/null
+++ b/spring-data-jpa/src/test/java/com/baeldung/ddd/event/Aggregate2EventsIntegrationTest.java
@@ -0,0 +1,68 @@
+/**
+ *
+ */
+package com.baeldung.ddd.event;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
+
+@SpringJUnitConfig
+@SpringBootTest
+class Aggregate2EventsIntegrationTest {
+ @MockBean
+ private TestEventHandler eventHandler;
+ @Autowired
+ private Aggregate2Repository repository;
+
+ // @formatter:off
+ @DisplayName("given aggregate with @AfterDomainEventPublication,"
+ + " when do domain operation and save twice,"
+ + " then an event is published only for the first time")
+ // @formatter:on
+ @Test
+ void afterDomainEvents() {
+ // given
+ Aggregate2 aggregate = new Aggregate2();
+
+ // when
+ aggregate.domainOperation();
+ repository.save(aggregate);
+ repository.save(aggregate);
+
+ // then
+ verify(eventHandler, times(1)).handleEvent(any(DomainEvent.class));
+ }
+
+ @BeforeEach
+ void beforeEach() {
+ repository.deleteAll();
+ }
+
+ // @formatter:off
+ @DisplayName("given aggregate with @DomainEvents,"
+ + " when do domain operation and save,"
+ + " then an event is published")
+ // @formatter:on
+ @Test
+ void domainEvents() {
+ // given
+ Aggregate2 aggregate = new Aggregate2();
+
+ // when
+ aggregate.domainOperation();
+ repository.save(aggregate);
+
+ // then
+ verify(eventHandler, times(1)).handleEvent(any(DomainEvent.class));
+ }
+
+}
diff --git a/spring-data-jpa/src/test/java/com/baeldung/ddd/event/Aggregate3EventsIntegrationTest.java b/spring-data-jpa/src/test/java/com/baeldung/ddd/event/Aggregate3EventsIntegrationTest.java
new file mode 100644
index 0000000000..893dcac3f8
--- /dev/null
+++ b/spring-data-jpa/src/test/java/com/baeldung/ddd/event/Aggregate3EventsIntegrationTest.java
@@ -0,0 +1,63 @@
+/**
+ *
+ */
+package com.baeldung.ddd.event;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
+
+@SpringJUnitConfig
+@SpringBootTest
+class Aggregate3EventsIntegrationTest {
+
+ @MockBean
+ private TestEventHandler eventHandler;
+ @Autowired
+ private Aggregate3Repository repository;
+
+ // @formatter:off
+ @DisplayName("given aggregate extending AbstractAggregateRoot,"
+ + " when do domain operation and save twice,"
+ + " then an event is published only for the first time")
+ // @formatter:on
+ @Test
+ void afterDomainEvents() {
+ // given
+ Aggregate3 aggregate = new Aggregate3();
+
+ // when
+ aggregate.domainOperation();
+ repository.save(aggregate);
+ repository.save(aggregate);
+
+ // then
+ verify(eventHandler, times(1)).handleEvent(any(DomainEvent.class));
+ }
+
+ // @formatter:off
+ @DisplayName("given aggregate extending AbstractAggregateRoot,"
+ + " when do domain operation and save,"
+ + " then an event is published")
+ // @formatter:on
+ @Test
+ void domainEvents() {
+ // given
+ Aggregate3 aggregate = new Aggregate3();
+
+ // when
+ aggregate.domainOperation();
+ repository.save(aggregate);
+
+ // then
+ verify(eventHandler, times(1)).handleEvent(any(DomainEvent.class));
+ }
+
+}
diff --git a/spring-data-jpa/src/test/java/com/baeldung/ddd/event/AggregateEventsIntegrationTest.java b/spring-data-jpa/src/test/java/com/baeldung/ddd/event/AggregateEventsIntegrationTest.java
new file mode 100644
index 0000000000..f0e1147245
--- /dev/null
+++ b/spring-data-jpa/src/test/java/com/baeldung/ddd/event/AggregateEventsIntegrationTest.java
@@ -0,0 +1,82 @@
+package com.baeldung.ddd.event;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.context.TestConfiguration;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.context.ApplicationEventPublisher;
+import org.springframework.context.annotation.Bean;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
+
+@SpringJUnitConfig
+@SpringBootTest
+class AggregateEventsIntegrationTest {
+
+ @Autowired
+ private DomainService domainService;
+
+ @MockBean
+ private TestEventHandler eventHandler;
+ @Autowired
+ private ApplicationEventPublisher eventPublisher;
+ @Autowired
+ private AggregateRepository repository;
+
+ // @formatter:off
+ @DisplayName("given existing aggregate,"
+ + " when do domain operation directly on aggregate,"
+ + " then domain event is NOT published")
+ // @formatter:on
+ @Test
+ void aggregateEventsTest() {
+ Aggregate existingDomainEntity = new Aggregate(0, eventPublisher);
+ repository.save(existingDomainEntity);
+
+ // when
+ repository.findById(existingDomainEntity.getId())
+ .get()
+ .domainOperation();
+
+ // then
+ verifyZeroInteractions(eventHandler);
+ }
+
+ @BeforeEach
+ void beforeEach() {
+ repository.deleteAll();
+ }
+
+ // @formatter:off
+ @DisplayName("given existing aggregate,"
+ + " when do domain operation on service,"
+ + " then domain event is published")
+ // @formatter:on
+ @Test
+ void serviceEventsTest() {
+ Aggregate existingDomainEntity = new Aggregate(1, eventPublisher);
+ repository.save(existingDomainEntity);
+
+ // when
+ domainService.serviceDomainOperation(existingDomainEntity.getId());
+
+ // then
+ verify(eventHandler, times(1)).handleEvent(any(DomainEvent.class));
+ }
+
+ @TestConfiguration
+ public static class TestConfig {
+ @Bean
+ public DomainService domainService(AggregateRepository repository, ApplicationEventPublisher eventPublisher) {
+ return new DomainService(repository, eventPublisher);
+ }
+ }
+
+}
diff --git a/spring-data-jpa/src/test/java/com/baeldung/ddd/event/TestEventHandler.java b/spring-data-jpa/src/test/java/com/baeldung/ddd/event/TestEventHandler.java
new file mode 100644
index 0000000000..721402c17a
--- /dev/null
+++ b/spring-data-jpa/src/test/java/com/baeldung/ddd/event/TestEventHandler.java
@@ -0,0 +1,12 @@
+/**
+ *
+ */
+package com.baeldung.ddd.event;
+
+import org.springframework.transaction.event.TransactionalEventListener;
+
+interface TestEventHandler {
+ @TransactionalEventListener
+ void handleEvent(DomainEvent event);
+
+}
diff --git a/spring-data-jpa/src/test/java/com/baeldung/services/JpaMultipleDBIntegrationTest.java b/spring-data-jpa/src/test/java/com/baeldung/services/JpaMultipleDBIntegrationTest.java
index 29b96ae597..71a3fb0b44 100644
--- a/spring-data-jpa/src/test/java/com/baeldung/services/JpaMultipleDBIntegrationTest.java
+++ b/spring-data-jpa/src/test/java/com/baeldung/services/JpaMultipleDBIntegrationTest.java
@@ -1,31 +1,33 @@
package com.baeldung.services;
-import com.baeldung.config.PersistenceProductConfiguration;
-import com.baeldung.config.PersistenceUserConfiguration;
-import com.baeldung.dao.repositories.user.PossessionRepository;
-import com.baeldung.dao.repositories.product.ProductRepository;
-import com.baeldung.dao.repositories.user.UserRepository;
-import com.baeldung.domain.user.Possession;
-import com.baeldung.domain.product.Product;
-import com.baeldung.domain.user.User;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.Collections;
+import java.util.Optional;
+
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.Transactional;
-import java.util.Collections;
-import java.util.Optional;
-
-import static org.junit.Assert.*;
+import com.baeldung.config.PersistenceProductConfiguration;
+import com.baeldung.config.PersistenceUserConfiguration;
+import com.baeldung.dao.repositories.product.ProductRepository;
+import com.baeldung.dao.repositories.user.PossessionRepository;
+import com.baeldung.dao.repositories.user.UserRepository;
+import com.baeldung.domain.product.Product;
+import com.baeldung.domain.user.Possession;
+import com.baeldung.domain.user.User;
@RunWith(SpringRunner.class)
-@ContextConfiguration(classes = {PersistenceUserConfiguration.class, PersistenceProductConfiguration.class})
+@ContextConfiguration(classes = { PersistenceUserConfiguration.class, PersistenceProductConfiguration.class })
@EnableTransactionManagement
@DirtiesContext
public class JpaMultipleDBIntegrationTest {
diff --git a/spring-data-jpa/src/test/java/com/baeldung/services/SpringDataJPABarAuditIntegrationTest.java b/spring-data-jpa/src/test/java/com/baeldung/services/SpringDataJPABarAuditIntegrationTest.java
index 3c36f43192..f3b857c73d 100644
--- a/spring-data-jpa/src/test/java/com/baeldung/services/SpringDataJPABarAuditIntegrationTest.java
+++ b/spring-data-jpa/src/test/java/com/baeldung/services/SpringDataJPABarAuditIntegrationTest.java
@@ -1,8 +1,16 @@
package com.baeldung.services;
-import com.baeldung.config.PersistenceConfiguration;
-import com.baeldung.domain.Bar;
-import org.junit.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -10,15 +18,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import com.baeldung.config.PersistenceConfiguration;
+import com.baeldung.domain.Bar;
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = { PersistenceConfiguration.class }, loader = AnnotationConfigContextLoader.class)
diff --git a/spring-mvc-java/README.md b/spring-mvc-java/README.md
index c4a0e3579c..44b1d65bc8 100644
--- a/spring-mvc-java/README.md
+++ b/spring-mvc-java/README.md
@@ -28,10 +28,5 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [The Spring @Controller and @RestController Annotations](http://www.baeldung.com/spring-controller-vs-restcontroller)
- [Spring MVC @PathVariable with a dot (.) gets truncated](http://www.baeldung.com/spring-mvc-pathvariable-dot)
- [A Quick Example of Spring Websockets’ @SendToUser Annotation](http://www.baeldung.com/spring-websockets-sendtouser)
-- [Spring Boot Annotations](http://www.baeldung.com/spring-boot-annotations)
-- [Spring Scheduling Annotations](http://www.baeldung.com/spring-scheduling-annotations)
-- [Spring Web Annotations](http://www.baeldung.com/spring-mvc-annotations)
-- [Spring Core Annotations](http://www.baeldung.com/spring-core-annotations)
- [Using Spring ResponseEntity to Manipulate the HTTP Response](http://www.baeldung.com/spring-response-entity)
- [Using Spring @ResponseStatus to Set HTTP Status Code](http://www.baeldung.com/spring-response-status)
-- [Display RSS Feed with Spring MVC](http://www.baeldung.com/spring-mvc-rss-feed)
diff --git a/spring-mvc-java/pom.xml b/spring-mvc-java/pom.xml
index 83f2556fe0..9d3e0ca1b2 100644
--- a/spring-mvc-java/pom.xml
+++ b/spring-mvc-java/pom.xml
@@ -5,70 +5,54 @@
spring-mvc-java
0.1-SNAPSHOT
spring-mvc-java
+ war
- parent-boot-2
+ parent-spring-5
com.baeldung
0.0.1-SNAPSHOT
- ../parent-boot-2
+ ../parent-spring-5
-
-
- org.springframework.boot
- spring-boot-starter-thymeleaf
+
+ org.springframework
+ spring-webmvc
+ ${spring.version}
-
- org.springframework.boot
- spring-boot-starter-actuator
-
-
- org.springframework.boot
- spring-boot-devtools
-
-
- org.springframework.boot
- spring-boot-test
- test
-
-
- org.springframework.boot
- spring-boot-starter-aop
-
-
- org.springframework.boot
- spring-boot-starter-web
-
-
- org.springframework.boot
- spring-boot-starter-websocket
-
-
-
-
- com.fasterxml.jackson.core
- jackson-databind
-
-
-
javax.servlet
javax.servlet-api
+ 4.0.1
+
+
+ javax.servlet.jsp
+ javax.servlet.jsp-api
+ 2.3.3
javax.servlet
jstl
+ ${jstl.version}
+
+
+
+
+ com.fasterxml.jackson.core
+ jackson-databind
+ ${jackson-databind.version}
org.aspectj
aspectjrt
+ 1.9.1
org.aspectj
aspectjweaver
+ 1.9.1
@@ -80,6 +64,7 @@
net.sourceforge.htmlunit
htmlunit
+ 2.32
commons-logging
@@ -104,10 +89,12 @@
com.jayway.jsonpath
json-path
test
+ 2.4.0
org.springframework
spring-test
+ ${spring.version}
test
@@ -120,34 +107,29 @@
- org.hibernate
+ org.hibernate.validator
hibernate-validator
${hibernate-validator.version}
-
- javax.el
- javax.el-api
- ${javax.el.version}
-
-
- org.glassfish.web
- javax.el
- ${javax.el.version}
-
com.google.code.gson
gson
+ 2.8.5
-
-
-
- com.rometools
- rome
- ${rome.version}
-
+
+ org.springframework
+ spring-websocket
+ ${spring.version}
+
+
+
+ org.springframework
+ spring-messaging
+ ${spring.version}
+
@@ -169,6 +151,7 @@
org.apache.maven.plugins
maven-war-plugin
+ ${maven-war-plugin.version}
false
@@ -262,7 +245,7 @@
3.0.9.RELEASE
- 5.2.5.Final
+ 6.0.10.Final
5.1.40
@@ -281,24 +264,19 @@
2.23
- 2.6
+ 3.2.2
2.7
1.6.1
3.1.0
- 1.8.9
+ 1.9.1
3.16-beta1
-
- 1.10.0
-
- 2.2.4
+ 3.0.1-b06
-
- com.baeldung.app.Application
diff --git a/spring-mvc-java/src/main/java/com/baeldung/app/Application.java b/spring-mvc-java/src/main/java/com/baeldung/app/Application.java
deleted file mode 100644
index 68d078de78..0000000000
--- a/spring-mvc-java/src/main/java/com/baeldung/app/Application.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.baeldung.app;
-
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
-import org.springframework.context.annotation.ComponentScan;
-
-@EnableAutoConfiguration
-@ComponentScan(value = {"com.baeldung.web.controller"}, resourcePattern = "**/FileUploadController.class")
-@SpringBootApplication
-public class Application extends SpringBootServletInitializer {
-
- public static void main(final String[] args) {
- SpringApplication.run(Application.class, args);
- }
-}
\ No newline at end of file
diff --git a/spring-mvc-java/src/main/java/com/baeldung/config/AppInitializer.java b/spring-mvc-java/src/main/java/com/baeldung/config/AppInitializer.java
index 9cf6e384f1..eec12f466f 100644
--- a/spring-mvc-java/src/main/java/com/baeldung/config/AppInitializer.java
+++ b/spring-mvc-java/src/main/java/com/baeldung/config/AppInitializer.java
@@ -14,13 +14,20 @@ public class AppInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext container) throws ServletException {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
- context.setConfigLocation("org.baeldung.config");
+
+ context.scan("com.baeldung");
container.addListener(new ContextLoaderListener(context));
- ServletRegistration.Dynamic dispatcher = container.addServlet("java-servlet", new DispatcherServlet(context));
+ ServletRegistration.Dynamic dispatcher = container.addServlet("mvc", new DispatcherServlet(context));
dispatcher.setLoadOnStartup(1);
- dispatcher.addMapping("/java-servlet/*");
+ dispatcher.addMapping("/");
+
+ // final MultipartConfigElement multipartConfigElement = new
+ // MultipartConfigElement(TMP_FOLDER, MAX_UPLOAD_SIZE,
+ // MAX_UPLOAD_SIZE * 2, MAX_UPLOAD_SIZE / 2);
+ //
+ // appServlet.setMultipartConfig(multipartConfigElement);
}
}
diff --git a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/ApplicationConfig.java b/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/ApplicationConfig.java
deleted file mode 100644
index 261d5793dc..0000000000
--- a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/ApplicationConfig.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package com.baeldung.spring.web.config;
-
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.ComponentScan;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.web.servlet.ViewResolver;
-import org.springframework.web.servlet.config.annotation.EnableWebMvc;
-import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
-import org.springframework.web.servlet.view.InternalResourceViewResolver;
-import org.springframework.web.servlet.view.JstlView;
-
-@EnableWebMvc
-@Configuration
-@ComponentScan(basePackages = { "com.baeldung.web.controller" })
-public class ApplicationConfig extends WebMvcConfigurerAdapter {
-
- public ApplicationConfig() {
- super();
- }
-
- @Override
- public void addViewControllers(final ViewControllerRegistry registry) {
- super.addViewControllers(registry);
- registry.addViewController("/").setViewName("index");
- }
-
- @Bean
- public ViewResolver viewResolver() {
- final InternalResourceViewResolver bean = new InternalResourceViewResolver();
- bean.setViewClass(JstlView.class);
- bean.setPrefix("/WEB-INF/jsp/");
- bean.setSuffix(".jsp");
- return bean;
- }
-}
\ No newline at end of file
diff --git a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/ClientWebConfig.java b/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/ClientWebConfig.java
deleted file mode 100644
index de47f9f69e..0000000000
--- a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/ClientWebConfig.java
+++ /dev/null
@@ -1,89 +0,0 @@
-package com.baeldung.spring.web.config;
-
-import javax.servlet.ServletContext;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.MessageSource;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Description;
-import org.springframework.context.support.ResourceBundleMessageSource;
-import org.springframework.web.servlet.ViewResolver;
-import org.springframework.web.servlet.config.annotation.EnableWebMvc;
-import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
-import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
-import org.springframework.web.servlet.view.InternalResourceViewResolver;
-import org.springframework.web.servlet.view.JstlView;
-import org.thymeleaf.spring4.SpringTemplateEngine;
-import org.thymeleaf.spring4.view.ThymeleafViewResolver;
-import org.thymeleaf.templateresolver.ServletContextTemplateResolver;
-
-@EnableWebMvc
-@Configuration
-public class ClientWebConfig implements WebMvcConfigurer {
-
- public ClientWebConfig() {
- super();
- }
-
- // API
-
- @Autowired
- private ServletContext ctx;
-
- @Override
- public void addViewControllers(final ViewControllerRegistry registry) {
-
- registry.addViewController("/sample.html");
- }
-
- @Bean
- public ViewResolver thymeleafViewResolver() {
- final ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
- viewResolver.setTemplateEngine(templateEngine());
- viewResolver.setOrder(1);
- return viewResolver;
- }
-
- @Bean
- public ViewResolver viewResolver() {
- final InternalResourceViewResolver bean = new InternalResourceViewResolver();
- bean.setViewClass(JstlView.class);
- bean.setPrefix("/WEB-INF/view/");
- bean.setSuffix(".jsp");
- bean.setOrder(0);
- return bean;
- }
-
- @Bean
- @Description("Thymeleaf template resolver serving HTML 5")
- public ServletContextTemplateResolver templateResolver() {
- final ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver(ctx);
- templateResolver.setPrefix("/WEB-INF/templates/");
- templateResolver.setSuffix(".html");
- templateResolver.setTemplateMode("HTML5");
- return templateResolver;
- }
-
- @Bean
- @Description("Thymeleaf template engine with Spring integration")
- public SpringTemplateEngine templateEngine() {
- final SpringTemplateEngine templateEngine = new SpringTemplateEngine();
- templateEngine.setTemplateResolver(templateResolver());
- return templateEngine;
- }
-
- @Bean
- @Description("Spring message resolver")
- public MessageSource messageSource() {
- final ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
- messageSource.setBasename("messages");
- return messageSource;
- }
-
- @Override
- public void addResourceHandlers(final ResourceHandlerRegistry registry) {
- registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
- }
-
-}
\ No newline at end of file
diff --git a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/ContentManagementWebConfig.java b/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/ContentManagementWebConfig.java
deleted file mode 100644
index 498105ded1..0000000000
--- a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/ContentManagementWebConfig.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package com.baeldung.spring.web.config;
-
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.http.MediaType;
-import org.springframework.web.servlet.ViewResolver;
-import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
-import org.springframework.web.servlet.config.annotation.EnableWebMvc;
-import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
-import org.springframework.web.servlet.view.InternalResourceViewResolver;
-import org.springframework.web.servlet.view.JstlView;
-
-@EnableWebMvc
-@Configuration
-public class ContentManagementWebConfig extends WebMvcConfigurerAdapter {
-
- public ContentManagementWebConfig() {
- super();
- }
-
- // API
-
- @Override
- public void configureContentNegotiation(final ContentNegotiationConfigurer configurer) {
- configurer.favorPathExtension(false).favorParameter(true).parameterName("mediaType").ignoreAcceptHeader(true).useJaf(false).defaultContentType(MediaType.APPLICATION_JSON).mediaType("xml", MediaType.APPLICATION_XML).mediaType("json",
- MediaType.APPLICATION_JSON);
- }
-
- @Override
- public void addViewControllers(final ViewControllerRegistry registry) {
- super.addViewControllers(registry);
- registry.addViewController("/sample.html");
- }
-
- @Bean
- public ViewResolver viewResolver() {
- final InternalResourceViewResolver bean = new InternalResourceViewResolver();
- bean.setViewClass(JstlView.class);
- bean.setPrefix("/WEB-INF/view/");
- bean.setSuffix(".jsp");
- bean.setOrder(0);
- return bean;
- }
-
-}
diff --git a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/MainWebAppInitializer.java b/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/MainWebAppInitializer.java
deleted file mode 100644
index 80ce22edd6..0000000000
--- a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/MainWebAppInitializer.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package com.baeldung.spring.web.config;
-
-import org.springframework.web.WebApplicationInitializer;
-import org.springframework.web.context.ContextLoaderListener;
-import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
-import org.springframework.web.context.support.GenericWebApplicationContext;
-import org.springframework.web.servlet.DispatcherServlet;
-
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRegistration;
-import java.util.Set;
-
-public class MainWebAppInitializer implements WebApplicationInitializer {
-
- private static final String TMP_FOLDER = "/tmp";
- private static final int MAX_UPLOAD_SIZE = 5 * 1024 * 1024; // 5 MB
-
- /**
- * Register and configure all Servlet container components necessary to power the web application.
- */
- @Override
- public void onStartup(final ServletContext sc) throws ServletException {
-
- // Create the 'root' Spring application context
- final AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();
- root.scan("com.baeldung.spring.web.config");
- // root.getEnvironment().setDefaultProfiles("embedded");
-
- sc.addListener(new ContextLoaderListener(root));
-
- // Handles requests into the application
- final ServletRegistration.Dynamic appServlet = sc.addServlet("mvc", new DispatcherServlet(new GenericWebApplicationContext()));
- appServlet.setLoadOnStartup(1);
-
- // final MultipartConfigElement multipartConfigElement = new
- // MultipartConfigElement(TMP_FOLDER, MAX_UPLOAD_SIZE,
- // MAX_UPLOAD_SIZE * 2, MAX_UPLOAD_SIZE / 2);
- //
- // appServlet.setMultipartConfig(multipartConfigElement);
-
- final Set mappingConflicts = appServlet.addMapping("/");
- if (!mappingConflicts.isEmpty()) {
- throw new IllegalStateException("'appServlet' could not be mapped to '/' due " + "to an existing mapping. This is a known issue under Tomcat versions " + "<= 7.0.14; see https://issues.apache.org/bugzilla/show_bug.cgi?id=51278");
- }
- }
-
-}
diff --git a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebConfig.java b/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebConfig.java
index 11be08a79d..191d721dfb 100644
--- a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebConfig.java
+++ b/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebConfig.java
@@ -3,40 +3,105 @@ package com.baeldung.spring.web.config;
import java.util.ArrayList;
import java.util.List;
+import javax.servlet.ServletContext;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Description;
+import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.MediaType;
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.ViewResolver;
+import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;
import org.springframework.web.servlet.view.ResourceBundleViewResolver;
import org.springframework.web.servlet.view.XmlViewResolver;
import org.springframework.web.util.UrlPathHelper;
-import com.baeldung.excel.*;
+import org.thymeleaf.spring4.SpringTemplateEngine;
+import org.thymeleaf.spring4.view.ThymeleafViewResolver;
+import org.thymeleaf.templateresolver.ServletContextTemplateResolver;
+
+import com.baeldung.excel.ExcelPOIHelper;
-@Configuration
@EnableWebMvc
-@ComponentScan("com.baeldung.web")
-public class WebConfig extends WebMvcConfigurerAdapter {
+@Configuration
+@ComponentScan(basePackages = { "com.baeldung.web.controller" })
+public class WebConfig implements WebMvcConfigurer {
- public WebConfig() {
- super();
+ @Autowired
+ private ServletContext ctx;
+
+ @Override
+ public void addViewControllers(final ViewControllerRegistry registry) {
+ registry.addViewController("/").setViewName("index");
+ }
+
+ @Bean
+ public ViewResolver thymeleafViewResolver() {
+ final ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
+ viewResolver.setTemplateEngine(templateEngine());
+ viewResolver.setOrder(1);
+ return viewResolver;
}
- // @Bean
- // public StandardServletMultipartResolver multipartResolver() {
- // return new StandardServletMultipartResolver();
- // }
+ @Bean
+ public ViewResolver viewResolver() {
+ final InternalResourceViewResolver bean = new InternalResourceViewResolver();
+ bean.setViewClass(JstlView.class);
+ bean.setPrefix("/WEB-INF/view/");
+ bean.setSuffix(".jsp");
+ bean.setOrder(0);
+ return bean;
+ }
+ @Bean
+ @Description("Thymeleaf template resolver serving HTML 5")
+ public ServletContextTemplateResolver templateResolver() {
+ final ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver(ctx);
+ templateResolver.setPrefix("/WEB-INF/templates/");
+ templateResolver.setSuffix(".html");
+ templateResolver.setTemplateMode("HTML5");
+ return templateResolver;
+ }
+
+ @Bean
+ @Description("Thymeleaf template engine with Spring integration")
+ public SpringTemplateEngine templateEngine() {
+ final SpringTemplateEngine templateEngine = new SpringTemplateEngine();
+ templateEngine.setTemplateResolver(templateResolver());
+ return templateEngine;
+ }
+
+ @Bean
+ @Description("Spring message resolver")
+ public MessageSource messageSource() {
+ final ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
+ messageSource.setBasename("messages");
+ return messageSource;
+ }
+
+ @Override
+ public void addResourceHandlers(final ResourceHandlerRegistry registry) {
+ registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
+ }
+
+ @Override
+ public void configureContentNegotiation(final ContentNegotiationConfigurer configurer) {
+ configurer.favorPathExtension(false).favorParameter(true).parameterName("mediaType").ignoreAcceptHeader(true).useRegisteredExtensionsOnly(false).defaultContentType(MediaType.APPLICATION_JSON).mediaType("xml", MediaType.APPLICATION_XML).mediaType("json",
+ MediaType.APPLICATION_JSON);
+ }
@Bean(name = "multipartResolver")
public CommonsMultipartResolver multipartResolver() {
@@ -45,23 +110,7 @@ public class WebConfig extends WebMvcConfigurerAdapter {
return multipartResolver;
}
-
- @Override
- public void addViewControllers(final ViewControllerRegistry registry) {
- super.addViewControllers(registry);
- registry.addViewController("/sample.html");
- }
-
- @Bean
- public ViewResolver internalResourceViewResolver() {
- final InternalResourceViewResolver bean = new InternalResourceViewResolver();
- bean.setViewClass(JstlView.class);
- bean.setPrefix("/WEB-INF/view/");
- bean.setSuffix(".jsp");
- bean.setOrder(2);
- return bean;
- }
-
+
@Bean
public ViewResolver xmlViewResolver() {
final XmlViewResolver bean = new XmlViewResolver();
@@ -112,5 +161,4 @@ public class WebConfig extends WebMvcConfigurerAdapter {
public ExcelPOIHelper excelPOIHelper() {
return new ExcelPOIHelper();
}
-
-}
+}
\ No newline at end of file
diff --git a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebSocketConfig.java b/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebSocketConfig.java
index 93ec13da58..0793658e90 100644
--- a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebSocketConfig.java
+++ b/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebSocketConfig.java
@@ -2,13 +2,13 @@ package com.baeldung.spring.web.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
-import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
+import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
@Configuration
@EnableWebSocketMessageBroker
-public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
+public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
@Override
public void configureMessageBroker(final MessageBrokerRegistry config) {
diff --git a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebSocketSendToUserConfig.java b/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebSocketSendToUserConfig.java
index 7f14380e5e..dbd52e20ba 100644
--- a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebSocketSendToUserConfig.java
+++ b/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebSocketSendToUserConfig.java
@@ -6,9 +6,9 @@ import org.springframework.http.server.ServerHttpResponse;
import org.springframework.http.server.ServletServerHttpRequest;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.WebSocketHandler;
-import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
+import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.server.support.DefaultHandshakeHandler;
import javax.servlet.http.HttpSession;
@@ -16,7 +16,7 @@ import java.util.Map;
@Configuration
@EnableWebSocketMessageBroker
-public class WebSocketSendToUserConfig extends AbstractWebSocketMessageBrokerConfigurer {
+public class WebSocketSendToUserConfig implements WebSocketMessageBrokerConfigurer {
@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/controller/SampleController.java b/spring-mvc-java/src/main/java/com/baeldung/web/controller/SampleController.java
new file mode 100644
index 0000000000..c13986e005
--- /dev/null
+++ b/spring-mvc-java/src/main/java/com/baeldung/web/controller/SampleController.java
@@ -0,0 +1,13 @@
+package com.baeldung.web.controller;
+
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+
+@Controller
+public class SampleController {
+ @GetMapping("/sample")
+ public String showForm() {
+ return "sample";
+ }
+
+}
diff --git a/spring-mvc-java/src/test/java/com/baeldung/web/controller/GreetControllerIntegrationTest.java b/spring-mvc-java/src/test/java/com/baeldung/web/controller/GreetControllerIntegrationTest.java
index b628228b7e..384bd85ec6 100644
--- a/spring-mvc-java/src/test/java/com/baeldung/web/controller/GreetControllerIntegrationTest.java
+++ b/spring-mvc-java/src/test/java/com/baeldung/web/controller/GreetControllerIntegrationTest.java
@@ -20,12 +20,12 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
-import com.baeldung.spring.web.config.ApplicationConfig;
+import com.baeldung.spring.web.config.WebConfig;
import com.baeldung.spring.web.config.WebConfig;
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
-@ContextConfiguration(classes = { ApplicationConfig.class, WebConfig.class })
+@ContextConfiguration(classes = { WebConfig.class, WebConfig.class })
public class GreetControllerIntegrationTest {
@Autowired
diff --git a/spring-swagger-codegen/spring-swagger-codegen-api-client/pom.xml b/spring-swagger-codegen/spring-swagger-codegen-api-client/pom.xml
index 0129875f60..0f1cfa27ac 100644
--- a/spring-swagger-codegen/spring-swagger-codegen-api-client/pom.xml
+++ b/spring-swagger-codegen/spring-swagger-codegen-api-client/pom.xml
@@ -54,20 +54,6 @@
pertest
-
- maven-dependency-plugin
-
-
- package
-
- copy-dependencies
-
-
- ${project.build.directory}/lib
-
-
-
-
diff --git a/testing-modules/testng/pom.xml b/testing-modules/testng/pom.xml
index 028db38727..a9f680aafb 100644
--- a/testing-modules/testng/pom.xml
+++ b/testing-modules/testng/pom.xml
@@ -38,24 +38,6 @@
true
-
-
- org.apache.maven.plugins
- maven-dependency-plugin
-
-
- copy-dependencies
- prepare-package
-
- copy-dependencies
-
-
- ${project.build.directory}/libs
-
-
-
-
-