diff --git a/apache-httpclient4/src/main/java/com/baeldung/filter/CustomWebSecurityConfigurerAdapter.java b/apache-httpclient4/src/main/java/com/baeldung/filter/CustomWebSecurityConfigurerAdapter.java
index fb597e46c8..eaf166a091 100644
--- a/apache-httpclient4/src/main/java/com/baeldung/filter/CustomWebSecurityConfigurerAdapter.java
+++ b/apache-httpclient4/src/main/java/com/baeldung/filter/CustomWebSecurityConfigurerAdapter.java
@@ -7,14 +7,14 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
-import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
+import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
@Configuration
@EnableWebSecurity
-public class CustomWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
+public class CustomWebSecurityConfigurerAdapter {
@Autowired private RestAuthenticationEntryPoint authenticationEntryPoint;
@@ -27,8 +27,8 @@ public class CustomWebSecurityConfigurerAdapter extends WebSecurityConfigurerAda
.authorities("ROLE_USER");
}
- @Override
- protected void configure(HttpSecurity http) throws Exception {
+ @Bean
+ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/securityNone")
@@ -40,6 +40,8 @@ public class CustomWebSecurityConfigurerAdapter extends WebSecurityConfigurerAda
.authenticationEntryPoint(authenticationEntryPoint);
http.addFilterAfter(new CustomFilter(), BasicAuthenticationFilter.class);
+
+ return http.build();
}
@Bean
diff --git a/apache-libraries/pom.xml b/apache-libraries/pom.xml
index c1def03bee..02e9f08a8d 100644
--- a/apache-libraries/pom.xml
+++ b/apache-libraries/pom.xml
@@ -191,7 +191,7 @@
2.0.6
2.0.1.Final
1.2.15
- 3.10.0
+ 4.12.0
1.2.15
1.2.15
1.2.15
diff --git a/core-java-modules/core-java-17/README.md b/core-java-modules/core-java-17/README.md
index 4b1125532d..44a4e760e1 100644
--- a/core-java-modules/core-java-17/README.md
+++ b/core-java-modules/core-java-17/README.md
@@ -9,3 +9,4 @@
- [Migrate From Java 8 to Java 17](https://www.baeldung.com/java-migrate-8-to-17)
- [Format Multiple ‘or’ Conditions in an If Statement in Java](https://www.baeldung.com/java-multiple-or-conditions-if-statement)
- [Get All Record Fields and Its Values via Reflection](https://www.baeldung.com/java-reflection-record-fields-values)
+- [Context-Specific Deserialization Filters in Java 17](https://www.baeldung.com/java-context-specific-deserialization-filters)
diff --git a/core-java-modules/core-java-arrays-convert/src/test/java/com/baeldung/array/conversions/ByteToCharArrayUnitTest.java b/core-java-modules/core-java-arrays-convert/src/test/java/com/baeldung/array/conversions/ByteToCharArrayUnitTest.java
new file mode 100644
index 0000000000..c62520cedc
--- /dev/null
+++ b/core-java-modules/core-java-arrays-convert/src/test/java/com/baeldung/array/conversions/ByteToCharArrayUnitTest.java
@@ -0,0 +1,47 @@
+package com.baeldung.array.conversions;
+
+import org.junit.Test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.StandardCharsets;
+
+import static org.junit.Assert.assertArrayEquals;
+
+public class ByteToCharArrayUnitTest {
+ public static byte[] byteArray = {65, 66, 67, 68};
+ public static char[] expected = {'A', 'B', 'C', 'D'};
+
+ @Test
+ public void givenByteArray_WhenUsingStandardCharsets_thenConvertToCharArray() {
+ char[] charArray = new String(byteArray, StandardCharsets.UTF_8).toCharArray();
+ assertArrayEquals(expected, charArray);
+ }
+
+ @Test
+ public void givenByteArray_WhenUsingSUsingStreams_thenConvertToCharArray() throws IOException {
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(byteArray);
+ InputStreamReader reader = new InputStreamReader(inputStream);
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ int data;
+ while ((data = reader.read()) != -1) {
+ char ch = (char) data;
+ outputStream.write(ch);
+ }
+ char[] charArray = outputStream.toString().toCharArray();
+ assertArrayEquals(expected, charArray);
+ }
+
+ @Test
+ public void givenByteArray_WhenUsingCharBuffer_thenConvertToCharArray() {
+ ByteBuffer byteBuffer = ByteBuffer.wrap(byteArray);
+ CharBuffer charBuffer = StandardCharsets.UTF_8.decode(byteBuffer);
+ char[] charArray = new char[charBuffer.remaining()];
+ charBuffer.get(charArray);
+ assertArrayEquals(expected, charArray);
+ }
+}
diff --git a/core-java-modules/core-java-collections-5/README.md b/core-java-modules/core-java-collections-5/README.md
index acee8154f7..c9fce58ac2 100644
--- a/core-java-modules/core-java-collections-5/README.md
+++ b/core-java-modules/core-java-collections-5/README.md
@@ -10,4 +10,5 @@
- [Remove Elements From a Queue Using Loop](https://www.baeldung.com/java-remove-elements-queue)
- [Intro to Vector Class in Java](https://www.baeldung.com/java-vector-guide)
- [HashSet toArray() Method in Java](https://www.baeldung.com/java-hashset-toarray)
+- [Time Complexity of Java Collections Sort in Java](https://www.baeldung.com/java-time-complexity-collections-sort)
- More articles: [[<-- prev]](/core-java-modules/core-java-collections-4)
diff --git a/core-java-modules/core-java-collections-maps-7/README.md b/core-java-modules/core-java-collections-maps-7/README.md
index a62bdda7af..c9f39dd2fa 100644
--- a/core-java-modules/core-java-collections-maps-7/README.md
+++ b/core-java-modules/core-java-collections-maps-7/README.md
@@ -4,4 +4,5 @@
- [How to Write Hashmap to CSV File](https://www.baeldung.com/java-write-hashmap-csv)
- [How to Get First or Last Entry From a LinkedHashMap in Java](https://www.baeldung.com/java-linkedhashmap-first-last-key-value-pair)
- [How to Write and Read a File with a Java HashMap](https://www.baeldung.com/java-hashmap-write-read-file)
+- [Limiting the Max Size of a HashMap in Java](https://www.baeldung.com/java-hashmap-max-size)
- More articles: [[<-- prev]](/core-java-modules/core-java-collections-maps-6)
\ No newline at end of file
diff --git a/core-java-modules/core-java-collections-maps-7/pom.xml b/core-java-modules/core-java-collections-maps-7/pom.xml
index a05b1b3528..2d08c0a438 100644
--- a/core-java-modules/core-java-collections-maps-7/pom.xml
+++ b/core-java-modules/core-java-collections-maps-7/pom.xml
@@ -38,6 +38,16 @@
guava
32.1.2-jre
+
+ org.openjdk.jmh
+ jmh-core
+ 1.37
+
+
+ org.openjdk.jmh
+ jmh-generator-annprocess
+ 1.37
+
diff --git a/core-java-modules/core-java-collections-maps-7/src/main/java/com/baeldung/map/HashMapWithMaxSizeLimit.java b/core-java-modules/core-java-collections-maps-7/src/main/java/com/baeldung/map/HashMapWithMaxSizeLimit.java
new file mode 100644
index 0000000000..63736e49f3
--- /dev/null
+++ b/core-java-modules/core-java-collections-maps-7/src/main/java/com/baeldung/map/HashMapWithMaxSizeLimit.java
@@ -0,0 +1,25 @@
+package com.baeldung.map;
+
+import java.util.HashMap;
+
+public class HashMapWithMaxSizeLimit extends HashMap {
+ private int maxSize = -1;
+
+ public HashMapWithMaxSizeLimit() {
+ super();
+ }
+
+ public HashMapWithMaxSizeLimit(int maxSize) {
+ super();
+ this.maxSize = maxSize;
+ }
+
+ @Override
+ public V put(K key, V value) {
+ if (this.maxSize == -1 || this.containsKey(key) || this.size() < this.maxSize) {
+ return super.put(key, value);
+ }
+ throw new RuntimeException("Max size exceeded!");
+ }
+
+}
diff --git a/core-java-modules/core-java-collections-maps-7/src/main/java/com/baeldung/map/BenchmarkMapMethods.java b/core-java-modules/core-java-collections-maps-7/src/main/java/com/baeldung/map/incrementmapkey/BenchmarkMapMethods.java
similarity index 99%
rename from core-java-modules/core-java-collections-maps-7/src/main/java/com/baeldung/map/BenchmarkMapMethods.java
rename to core-java-modules/core-java-collections-maps-7/src/main/java/com/baeldung/map/incrementmapkey/BenchmarkMapMethods.java
index eca028efe4..563b2ffdae 100644
--- a/core-java-modules/core-java-collections-maps-7/src/main/java/com/baeldung/map/BenchmarkMapMethods.java
+++ b/core-java-modules/core-java-collections-maps-7/src/main/java/com/baeldung/map/incrementmapkey/BenchmarkMapMethods.java
@@ -1,4 +1,4 @@
-package com.baeldung.map;
+package com.baeldung.map.incrementmapkey;
import java.util.HashMap;
import java.util.Map;
diff --git a/core-java-modules/core-java-collections-maps-7/src/main/java/com/baeldung/map/incrementmapkey/BenchmarkMapMethodsJMH.java b/core-java-modules/core-java-collections-maps-7/src/main/java/com/baeldung/map/incrementmapkey/BenchmarkMapMethodsJMH.java
new file mode 100644
index 0000000000..4ddf3886e9
--- /dev/null
+++ b/core-java-modules/core-java-collections-maps-7/src/main/java/com/baeldung/map/incrementmapkey/BenchmarkMapMethodsJMH.java
@@ -0,0 +1,68 @@
+package com.baeldung.map.incrementmapkey;
+
+import java.util.concurrent.TimeUnit;
+
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.State;
+
+@State(Scope.Benchmark)
+public class BenchmarkMapMethodsJMH {
+ @Benchmark
+ @BenchmarkMode(Mode.AverageTime)
+ @OutputTimeUnit(TimeUnit.NANOSECONDS)
+ @Fork(value = 1, warmups = 1)
+ public void benchMarkGuavaMap() {
+ IncrementMapValueWays im = new IncrementMapValueWays();
+ im.charFrequencyUsingAtomicMap(getString());
+ }
+
+ @Benchmark
+ @BenchmarkMode(Mode.AverageTime)
+ @OutputTimeUnit(TimeUnit.NANOSECONDS)
+ @Fork(value = 1, warmups = 1)
+ public void benchContainsKeyMap() {
+ IncrementMapValueWays im = new IncrementMapValueWays();
+ im.charFrequencyUsingContainsKey(getString());
+ }
+
+ @Benchmark
+ @BenchmarkMode(Mode.AverageTime)
+ @OutputTimeUnit(TimeUnit.NANOSECONDS)
+ @Fork(value = 1, warmups = 1)
+ public void benchMarkComputeMethod() {
+ IncrementMapValueWays im = new IncrementMapValueWays();
+ im.charFrequencyUsingCompute(getString());
+ }
+
+ @Benchmark
+ @BenchmarkMode(Mode.AverageTime)
+ @OutputTimeUnit(TimeUnit.NANOSECONDS)
+ @Fork(value = 1, warmups = 1)
+ public void benchMarkMergeMethod() {
+ IncrementMapValueWays im = new IncrementMapValueWays();
+ im.charFrequencyUsingMerge(getString());
+ }
+
+ public static void main(String[] args) throws Exception {
+ org.openjdk.jmh.Main.main(args);
+ }
+
+ private String getString() {
+ return
+ "Once upon a time in a quaint village nestled between rolling hills and whispering forests, there lived a solitary storyteller named Elias. Elias was known for spinning tales that transported listeners to magical realms and awakened forgotten dreams.\n"
+ + "\n"
+ + "His favorite spot was beneath an ancient oak tree, its sprawling branches offering shade to those who sought refuge from the bustle of daily life. Villagers of all ages would gather around Elias, their faces illuminated by the warmth of his stories.\n"
+ + "\n" + "One evening, as dusk painted the sky in hues of orange and purple, a curious young girl named Lily approached Elias. Her eyes sparkled with wonder as she asked for a tale unlike any other.\n" + "\n"
+ + "Elias smiled, sensing her thirst for adventure, and began a story about a forgotten kingdom veiled by mist, guarded by mystical creatures and enchanted by ancient spells. With each word, the air grew thick with anticipation, and the listeners were transported into a world where magic danced on the edges of reality.\n"
+ + "\n" + "As Elias weaved the story, Lily's imagination took flight. She envisioned herself as a brave warrior, wielding a shimmering sword against dark forces, her heart fueled by courage and kindness.\n" + "\n"
+ + "The night wore on, but the spell of the tale held everyone captive. The villagers laughed, gasped, and held their breaths, journeying alongside the characters through trials and triumphs.\n" + "\n"
+ + "As the final words lingered in the air, a sense of enchantment settled upon the listeners. They thanked Elias for the gift of his storytelling, each carrying a piece of the magical kingdom within their hearts.\n" + "\n"
+ + "Lily, inspired by the story, vowed to cherish the spirit of adventure and kindness in her own life. With a newfound spark in her eyes, she bid Elias goodnight, already dreaming of the countless adventures awaiting her.\n" + "\n"
+ + "Under the star-studded sky, Elias remained beneath the ancient oak, his heart aglow with the joy of sharing tales that ignited imagination and inspired dreams. And as the night embraced the village, whispers of the enchanted kingdom lingered in the breeze, promising endless possibilities to those who dared to believe.";
+ }
+}
diff --git a/core-java-modules/core-java-collections-maps-7/src/main/java/com/baeldung/map/IncrementMapValueWays.java b/core-java-modules/core-java-collections-maps-7/src/main/java/com/baeldung/map/incrementmapkey/IncrementMapValueWays.java
similarity index 98%
rename from core-java-modules/core-java-collections-maps-7/src/main/java/com/baeldung/map/IncrementMapValueWays.java
rename to core-java-modules/core-java-collections-maps-7/src/main/java/com/baeldung/map/incrementmapkey/IncrementMapValueWays.java
index 70b3c6c54d..e15b3aae8e 100644
--- a/core-java-modules/core-java-collections-maps-7/src/main/java/com/baeldung/map/IncrementMapValueWays.java
+++ b/core-java-modules/core-java-collections-maps-7/src/main/java/com/baeldung/map/incrementmapkey/IncrementMapValueWays.java
@@ -1,4 +1,4 @@
-package com.baeldung.map;
+package com.baeldung.map.incrementmapkey;
import java.util.HashMap;
import java.util.Map;
diff --git a/core-java-modules/core-java-collections-maps-7/src/test/java/com/baeldung/map/LimitMaxSizeHashMapByCustomHashMapUnitTest.java b/core-java-modules/core-java-collections-maps-7/src/test/java/com/baeldung/map/LimitMaxSizeHashMapByCustomHashMapUnitTest.java
new file mode 100644
index 0000000000..0846baae1a
--- /dev/null
+++ b/core-java-modules/core-java-collections-maps-7/src/test/java/com/baeldung/map/LimitMaxSizeHashMapByCustomHashMapUnitTest.java
@@ -0,0 +1,60 @@
+package com.baeldung.map;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import org.junit.jupiter.api.Test;
+
+class LimitMaxSizeHashMapByCustomHashMapUnitTest {
+
+ private final int MAX_SIZE = 4;
+ private HashMapWithMaxSizeLimit hashMapWithMaxSizeLimit;
+
+ @Test
+ void givenCustomHashMapObject_whenThereIsNoLimit_thenDoesNotThrowException() {
+ hashMapWithMaxSizeLimit = new HashMapWithMaxSizeLimit();
+ assertDoesNotThrow(() -> {
+ for (int i = 0; i < 10000; i++) {
+ hashMapWithMaxSizeLimit.put(i, i + "");
+ }
+ });
+ }
+
+ @Test
+ void givenCustomHashMapObject_whenLimitNotReached_thenDoesNotThrowException() {
+ hashMapWithMaxSizeLimit = new HashMapWithMaxSizeLimit(MAX_SIZE);
+ assertDoesNotThrow(() -> {
+ for (int i = 0; i < 4; i++) {
+ hashMapWithMaxSizeLimit.put(i, i + "");
+ }
+ });
+ }
+
+ @Test
+ void givenCustomHashMapObject_whenReplacingValueWhenLimitIsReached_thenDoesNotThrowException() {
+ hashMapWithMaxSizeLimit = new HashMapWithMaxSizeLimit(MAX_SIZE);
+ assertDoesNotThrow(() -> {
+ hashMapWithMaxSizeLimit.put(1, "One");
+ hashMapWithMaxSizeLimit.put(2, "Two");
+ hashMapWithMaxSizeLimit.put(3, "Three");
+ hashMapWithMaxSizeLimit.put(4, "Four");
+ hashMapWithMaxSizeLimit.put(4, "4");
+ });
+ }
+
+ @Test
+ void givenCustomHashMapObject_whenLimitExceeded_thenThrowsException() {
+ hashMapWithMaxSizeLimit = new HashMapWithMaxSizeLimit(MAX_SIZE);
+ Exception exception = assertThrows(RuntimeException.class, () -> {
+ for (int i = 0; i < 5; i++) {
+ hashMapWithMaxSizeLimit.put(i, i + "");
+ }
+ });
+
+ String messageThrownWhenSizeExceedsLimit = "Max size exceeded!";
+ String actualMessage = exception.getMessage();
+ assertTrue(actualMessage.equals(messageThrownWhenSizeExceedsLimit));
+ }
+
+}
diff --git a/core-java-modules/core-java-collections-maps-7/src/test/java/com/baeldung/map/LimitMaxSizeHashMapByLinkedHashMapUnitTest.java b/core-java-modules/core-java-collections-maps-7/src/test/java/com/baeldung/map/LimitMaxSizeHashMapByLinkedHashMapUnitTest.java
new file mode 100644
index 0000000000..d32d98da3a
--- /dev/null
+++ b/core-java-modules/core-java-collections-maps-7/src/test/java/com/baeldung/map/LimitMaxSizeHashMapByLinkedHashMapUnitTest.java
@@ -0,0 +1,38 @@
+package com.baeldung.map;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import org.junit.jupiter.api.Test;
+
+class LimitMaxSizeHashMapByLinkedHashMapUnitTest {
+
+ @Test
+ void givenLinkedHashMapObject_whenAddingNewEntry_thenEldestEntryIsRemoved() {
+ final int MAX_SIZE = 4;
+ LinkedHashMap linkedHashMap;
+ linkedHashMap = new LinkedHashMap() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected boolean removeEldestEntry(Map.Entry eldest) {
+ return size() > MAX_SIZE;
+ }
+ };
+ linkedHashMap.put(1, "One");
+ linkedHashMap.put(2, "Two");
+ linkedHashMap.put(3, "Three");
+ linkedHashMap.put(4, "Four");
+ linkedHashMap.put(5, "Five");
+ String[] expectedArrayAfterFive = { "Two", "Three", "Four", "Five" };
+ assertArrayEquals(expectedArrayAfterFive, linkedHashMap.values()
+ .toArray());
+ linkedHashMap.put(6, "Six");
+ String[] expectedArrayAfterSix = { "Three", "Four", "Five", "Six" };
+ assertArrayEquals(expectedArrayAfterSix, linkedHashMap.values()
+ .toArray());
+ }
+
+}
diff --git a/core-java-modules/core-java-collections-maps-7/src/test/java/com/baeldung/map/LinkedHashMapSortByValueUnitTest.java b/core-java-modules/core-java-collections-maps-7/src/test/java/com/baeldung/map/LinkedHashMapSortByValueUnitTest.java
new file mode 100644
index 0000000000..8fd62cc20b
--- /dev/null
+++ b/core-java-modules/core-java-collections-maps-7/src/test/java/com/baeldung/map/LinkedHashMapSortByValueUnitTest.java
@@ -0,0 +1,141 @@
+package com.baeldung.map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
+import org.junit.jupiter.api.Test;
+
+class Player {
+ private String name;
+ private Integer score = 0;
+
+ public Player(String name, Integer score) {
+ this.name = name;
+ this.score = score;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof Player)) {
+ return false;
+ }
+
+ Player player = (Player) o;
+
+ if (!Objects.equals(name, player.name)) {
+ return false;
+ }
+ return Objects.equals(score, player.score);
+ }
+
+ @Override
+ public int hashCode() {
+ int result = name != null ? name.hashCode() : 0;
+ result = 31 * result + (score != null ? score.hashCode() : 0);
+ return result;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getScore() {
+ return score;
+ }
+}
+
+public class LinkedHashMapSortByValueUnitTest {
+ private static LinkedHashMap MY_MAP = new LinkedHashMap<>();
+
+ static {
+ MY_MAP.put("key a", 4);
+ MY_MAP.put("key b", 1);
+ MY_MAP.put("key c", 3);
+ MY_MAP.put("key d", 2);
+ MY_MAP.put("key e", 5);
+ }
+
+ private static LinkedHashMap EXPECTED_MY_MAP = new LinkedHashMap<>();
+
+ static {
+ EXPECTED_MY_MAP.put("key b", 1);
+ EXPECTED_MY_MAP.put("key d", 2);
+ EXPECTED_MY_MAP.put("key c", 3);
+ EXPECTED_MY_MAP.put("key a", 4);
+ EXPECTED_MY_MAP.put("key e", 5);
+ }
+
+ private static final LinkedHashMap PLAYERS = new LinkedHashMap<>();
+ static {
+ PLAYERS.put("player a", new Player("Eric", 9));
+ PLAYERS.put("player b", new Player("Kai", 7));
+ PLAYERS.put("player c", new Player("Amanda", 20));
+ PLAYERS.put("player d", new Player("Kevin", 4));
+ }
+
+ private static final LinkedHashMap EXPECTED_PLAYERS = new LinkedHashMap<>();
+
+ static {
+ EXPECTED_PLAYERS.put("player d", new Player("Kevin", 4));
+ EXPECTED_PLAYERS.put("player b", new Player("Kai", 7));
+ EXPECTED_PLAYERS.put("player a", new Player("Eric", 9));
+ EXPECTED_PLAYERS.put("player c", new Player("Amanda", 20));
+ }
+
+ @Test
+ void whenUsingCollectionSort_thenGetExpectedResult() {
+ List> entryList = new ArrayList<>(MY_MAP.entrySet());
+ Collections.sort(entryList, new Comparator>() {
+ @Override
+ public int compare(Map.Entry o1, Map.Entry o2) {
+ return o1.getValue()
+ .compareTo(o2.getValue());
+ }
+ });
+
+ LinkedHashMap result = new LinkedHashMap<>();
+ for (Map.Entry e : entryList) {
+ result.put(e.getKey(), e.getValue());
+ }
+ assertEquals(EXPECTED_MY_MAP, result);
+ }
+
+ @Test
+ void whenUsingEntrycomparingByValueAndFillAMap_thenGetExpectedResult() {
+ LinkedHashMap result = new LinkedHashMap<>();
+ MY_MAP.entrySet()
+ .stream()
+ .sorted(Map.Entry.comparingByValue())
+ .forEachOrdered(entry -> result.put(entry.getKey(), entry.getValue()));
+ assertEquals(EXPECTED_MY_MAP, result);
+ }
+
+ @Test
+ void whenUsingEntrycomparingByValueAndCollect_thenGetExpectedResult() {
+ LinkedHashMap result = MY_MAP.entrySet()
+ .stream()
+ .sorted(Map.Entry.comparingByValue())
+ .collect(LinkedHashMap::new, (map, entry) -> map.put(entry.getKey(), entry.getValue()), Map::putAll);
+ assertEquals(EXPECTED_MY_MAP, result);
+ }
+
+ @Test
+ void whenUsingEntrycomparingByValueAndComparator_thenGetExpectedResult() {
+ LinkedHashMap result = PLAYERS.entrySet()
+ .stream()
+ .sorted(Map.Entry.comparingByValue(Comparator.comparing(Player::getScore)))
+ .collect(LinkedHashMap::new, (map, entry) -> map.put(entry.getKey(), entry.getValue()), Map::putAll);
+ assertEquals(EXPECTED_PLAYERS, result);
+ }
+
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-collections-maps-7/src/test/java/com/baeldung/map/IncrementMapValueUnitTest.java b/core-java-modules/core-java-collections-maps-7/src/test/java/com/baeldung/map/incrementmapkey/IncrementMapValueUnitTest.java
similarity index 97%
rename from core-java-modules/core-java-collections-maps-7/src/test/java/com/baeldung/map/IncrementMapValueUnitTest.java
rename to core-java-modules/core-java-collections-maps-7/src/test/java/com/baeldung/map/incrementmapkey/IncrementMapValueUnitTest.java
index df4f2b787e..64b9e1155d 100644
--- a/core-java-modules/core-java-collections-maps-7/src/test/java/com/baeldung/map/IncrementMapValueUnitTest.java
+++ b/core-java-modules/core-java-collections-maps-7/src/test/java/com/baeldung/map/incrementmapkey/IncrementMapValueUnitTest.java
@@ -1,4 +1,4 @@
-package com.baeldung.map;
+package com.baeldung.map.incrementmapkey;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -9,6 +9,8 @@ import java.util.stream.Stream;
import org.junit.Assert;
import org.junit.Test;
+import com.baeldung.map.incrementmapkey.IncrementMapValueWays;
+
public class IncrementMapValueUnitTest {
@Test
diff --git a/core-java-modules/core-java-concurrency-advanced-5/README.md b/core-java-modules/core-java-concurrency-advanced-5/README.md
index ba845a7c4b..d991b6cc34 100644
--- a/core-java-modules/core-java-concurrency-advanced-5/README.md
+++ b/core-java-modules/core-java-concurrency-advanced-5/README.md
@@ -1,3 +1,4 @@
### Relevant Articles:
- [Why wait() Requires Synchronization?](https://www.baeldung.com/java-wait-necessary-synchronization)
+- [Working with Exceptions in Java CompletableFuture](https://www.baeldung.com/java-exceptions-completablefuture)
diff --git a/core-java-modules/core-java-concurrency-advanced-5/src/main/java/com/baeldung/wait_synchronization/ConditionChecker.java b/core-java-modules/core-java-concurrency-advanced-5/src/main/java/com/baeldung/wait_synchronization/ConditionChecker.java
index dca36fe7cb..34e0a7522b 100644
--- a/core-java-modules/core-java-concurrency-advanced-5/src/main/java/com/baeldung/wait_synchronization/ConditionChecker.java
+++ b/core-java-modules/core-java-concurrency-advanced-5/src/main/java/com/baeldung/wait_synchronization/ConditionChecker.java
@@ -2,7 +2,7 @@ package com.baeldung.wait_synchronization;
public class ConditionChecker {
- private volatile Boolean jobIsDone;
+ private volatile boolean jobIsDone;
private final Object lock = new Object();
public void ensureCondition() {
@@ -21,4 +21,4 @@ public class ConditionChecker {
lock.notify();
}
}
-}
\ No newline at end of file
+}
diff --git a/core-java-modules/core-java-console/pom.xml b/core-java-modules/core-java-console/pom.xml
index 8677b672ea..a761b2749e 100644
--- a/core-java-modules/core-java-console/pom.xml
+++ b/core-java-modules/core-java-console/pom.xml
@@ -159,7 +159,7 @@
- 3.0.0-M1
+ 3.6.2
1.8
1.8
0.3.2
diff --git a/core-java-modules/core-java-datetime-conversion/README.md b/core-java-modules/core-java-datetime-conversion/README.md
index d3a3dae728..c7ba333222 100644
--- a/core-java-modules/core-java-datetime-conversion/README.md
+++ b/core-java-modules/core-java-datetime-conversion/README.md
@@ -10,3 +10,4 @@ This module contains articles about converting between Java date and time object
- [Convert Between LocalDateTime and ZonedDateTime](https://www.baeldung.com/java-localdatetime-zoneddatetime)
- [Conversion From 12-Hour Time to 24-Hour Time in Java](https://www.baeldung.com/java-convert-time-format)
- [Convert Epoch Time to LocalDate and LocalDateTime](https://www.baeldung.com/java-convert-epoch-localdate)
+- [Convert Timestamp String to Long in Java](https://www.baeldung.com/java-convert-timestamp-string-long)
diff --git a/core-java-modules/core-java-documentation/pom.xml b/core-java-modules/core-java-documentation/pom.xml
index be18af1b10..23443dd5ea 100644
--- a/core-java-modules/core-java-documentation/pom.xml
+++ b/core-java-modules/core-java-documentation/pom.xml
@@ -33,7 +33,7 @@
- 3.0.0-M1
+ 3.6.2
1.8
1.8
diff --git a/core-java-modules/core-java-io-2/pom.xml b/core-java-modules/core-java-io-2/pom.xml
index 8632748baa..830b386fe2 100644
--- a/core-java-modules/core-java-io-2/pom.xml
+++ b/core-java-modules/core-java-io-2/pom.xml
@@ -61,7 +61,7 @@
- 3.0.0-M1
+ 3.6.2
3.3.1
diff --git a/core-java-modules/core-java-io-conversions-2/src/main/java/com/baeldung/csv/WriteCsvFileExample.java b/core-java-modules/core-java-io-conversions-2/src/main/java/com/baeldung/csv/WriteCsvFileExample.java
index f409d05b06..184ae6d3e3 100644
--- a/core-java-modules/core-java-io-conversions-2/src/main/java/com/baeldung/csv/WriteCsvFileExample.java
+++ b/core-java-modules/core-java-io-conversions-2/src/main/java/com/baeldung/csv/WriteCsvFileExample.java
@@ -12,6 +12,10 @@ public class WriteCsvFileExample {
}
public String escapeSpecialCharacters(String data) {
+ if (data == null) {
+ throw new IllegalArgumentException("Input data cannot be null");
+ }
+
String escapedData = data.replaceAll("\\R", " ");
if (data.contains(",") || data.contains("\"") || data.contains("'")) {
data = data.replace("\"", "\"\"");
diff --git a/core-java-modules/core-java-io/pom.xml b/core-java-modules/core-java-io/pom.xml
index faeddafd81..93c9289fdd 100644
--- a/core-java-modules/core-java-io/pom.xml
+++ b/core-java-modules/core-java-io/pom.xml
@@ -134,7 +134,7 @@
- 3.5.0
+ 3.6.2
2.7.1
2.8.0
diff --git a/core-java-modules/core-java-ipc/pom.xml b/core-java-modules/core-java-ipc/pom.xml
new file mode 100644
index 0000000000..b7b37afb1d
--- /dev/null
+++ b/core-java-modules/core-java-ipc/pom.xml
@@ -0,0 +1,16 @@
+
+
+ 4.0.0
+ core-java-ipc
+ core-java-ipc
+ jar
+
+
+ com.baeldung.core-java-modules
+ core-java-modules
+ 0.0.1-SNAPSHOT
+
+
+
diff --git a/core-java-modules/core-java-ipc/src/test/java/com/baeldung/ipc/DirectoryLiveTest.java b/core-java-modules/core-java-ipc/src/test/java/com/baeldung/ipc/DirectoryLiveTest.java
new file mode 100644
index 0000000000..ca7b6d2a0e
--- /dev/null
+++ b/core-java-modules/core-java-ipc/src/test/java/com/baeldung/ipc/DirectoryLiveTest.java
@@ -0,0 +1,32 @@
+package com.baeldung.ipc;
+
+import org.junit.jupiter.api.Test;
+
+import java.nio.file.FileSystems;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardWatchEventKinds;
+import java.nio.file.WatchKey;
+import java.nio.file.WatchEvent;
+import java.nio.file.WatchService;
+
+
+public class DirectoryLiveTest {
+ @Test
+ public void consumer() throws Exception {
+ WatchService watchService = FileSystems.getDefault().newWatchService();
+ // Set this to an appropriate directory.
+ Path path = Paths.get("/tmp/ipc");
+
+ path.register(watchService, StandardWatchEventKinds.ENTRY_CREATE);
+
+ WatchKey key;
+ while ((key = watchService.take()) != null) {
+ for (WatchEvent> event : key.pollEvents()) {
+ // React to new file.
+ System.out.println(event);
+ }
+ key.reset();
+ }
+ }
+}
diff --git a/core-java-modules/core-java-ipc/src/test/java/com/baeldung/ipc/JmxLiveTest.java b/core-java-modules/core-java-ipc/src/test/java/com/baeldung/ipc/JmxLiveTest.java
new file mode 100644
index 0000000000..8ac16fdfc3
--- /dev/null
+++ b/core-java-modules/core-java-ipc/src/test/java/com/baeldung/ipc/JmxLiveTest.java
@@ -0,0 +1,52 @@
+package com.baeldung.ipc;
+
+import org.junit.jupiter.api.Test;
+
+import javax.management.JMX;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXServiceURL;
+import java.lang.management.ManagementFactory;
+import java.util.concurrent.TimeUnit;
+
+public class JmxLiveTest {
+ /*
+ * This test needs to be run with the following system properties defined:
+ * -Dcom.sun.management.jmxremote=true
+ * -Dcom.sun.management.jmxremote.port=1234
+ * -Dcom.sun.management.jmxremote.authenticate=false
+ * -Dcom.sun.management.jmxremote.ssl=false
+ */
+ @Test
+ public void consumer() throws Exception {
+ ObjectName objectName = new ObjectName("com.baeldung.ipc:type=basic,name=test");
+ MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+ server.registerMBean(new IPCTest(), objectName);
+
+ TimeUnit.MINUTES.sleep(50);
+ }
+
+ @Test
+ public void producer() throws Exception {
+ JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1234/jmxrmi");
+ try (JMXConnector jmxc = JMXConnectorFactory.connect(url, null)) {
+ ObjectName objectName = new ObjectName("com.baeldung.ipc:type=basic,name=test");
+
+ IPCTestMBean mbeanProxy = JMX.newMBeanProxy(jmxc.getMBeanServerConnection(), objectName, IPCTestMBean.class, true);
+ mbeanProxy.sendMessage("Hello");
+ }
+ }
+
+ public interface IPCTestMBean {
+ void sendMessage(String message);
+ }
+
+ class IPCTest implements IPCTestMBean {
+ @Override
+ public void sendMessage(String message) {
+ System.out.println("Received message: " + message);
+ }
+ }
+}
diff --git a/core-java-modules/core-java-ipc/src/test/java/com/baeldung/ipc/SocketsLiveTest.java b/core-java-modules/core-java-ipc/src/test/java/com/baeldung/ipc/SocketsLiveTest.java
new file mode 100644
index 0000000000..9b006c110e
--- /dev/null
+++ b/core-java-modules/core-java-ipc/src/test/java/com/baeldung/ipc/SocketsLiveTest.java
@@ -0,0 +1,38 @@
+package com.baeldung.ipc;
+
+import org.junit.jupiter.api.Test;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.net.ServerSocket;
+import java.net.Socket;
+
+public class SocketsLiveTest {
+ @Test
+ public void consumer() throws Exception {
+ try (ServerSocket serverSocket = new ServerSocket(1234)) {
+ Socket clientSocket = serverSocket.accept();
+
+ PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
+ BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
+
+ String line;
+ while ((line = in.readLine()) != null) {
+ System.out.println("Received message: " + line);
+ }
+ }
+ }
+
+ @Test
+ public void producer() throws Exception {
+ try (Socket clientSocket = new Socket("localhost", 1234)) {
+ PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
+ BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
+
+ out.println("Hello");
+
+ String response = in.readLine();
+ }
+ }
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-jar/pom.xml b/core-java-modules/core-java-jar/pom.xml
index a46299c669..138827781e 100644
--- a/core-java-modules/core-java-jar/pom.xml
+++ b/core-java-modules/core-java-jar/pom.xml
@@ -274,7 +274,7 @@
4.6.1
1.1
- 3.0.0-M1
+ 3.6.2
1.4.4
3.1.1
3.3.0
diff --git a/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/returnfirstnonnull/LazyEvaluate.java b/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/returnfirstnonnull/LazyEvaluate.java
new file mode 100644
index 0000000000..faa6cce465
--- /dev/null
+++ b/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/returnfirstnonnull/LazyEvaluate.java
@@ -0,0 +1,16 @@
+package com.baeldung.returnfirstnonnull;
+
+class LazyEvaluate {
+
+ String methodA() {
+ return null;
+ }
+
+ String methodB() {
+ return "first non null";
+ }
+
+ String methodC() {
+ return "second non null";
+ }
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-lang-6/src/test/java/com/baeldung/returnfirstnonempty/ReturnFirstNonEmptyOptionalUnitTest.java b/core-java-modules/core-java-lang-6/src/test/java/com/baeldung/returnfirstnonempty/ReturnFirstNonEmptyOptionalUnitTest.java
new file mode 100644
index 0000000000..f2ea8f74e3
--- /dev/null
+++ b/core-java-modules/core-java-lang-6/src/test/java/com/baeldung/returnfirstnonempty/ReturnFirstNonEmptyOptionalUnitTest.java
@@ -0,0 +1,30 @@
+package com.baeldung.returnfirstnonempty;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+public class ReturnFirstNonEmptyOptionalUnitTest {
+
+ private List> optionals;
+
+ @BeforeEach
+ public void init() {
+ optionals = Arrays.asList(Optional. empty(), Optional.of("first non empty"), Optional.of("second non empty"));
+ }
+
+ @Test
+ void givenListOfOptionals_whenStreaming_thenReturnFirstNonEmpty() {
+ Optional object = optionals.stream()
+ .filter(Optional::isPresent)
+ .map(Optional::get)
+ .findFirst();
+
+ assertThat(object).contains("first non empty");
+ }
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-lang-6/src/test/java/com/baeldung/returnfirstnonnull/ReturnFirstNonNullLazyEvaluateUnitTest.java b/core-java-modules/core-java-lang-6/src/test/java/com/baeldung/returnfirstnonnull/ReturnFirstNonNullLazyEvaluateUnitTest.java
new file mode 100644
index 0000000000..af88545170
--- /dev/null
+++ b/core-java-modules/core-java-lang-6/src/test/java/com/baeldung/returnfirstnonnull/ReturnFirstNonNullLazyEvaluateUnitTest.java
@@ -0,0 +1,77 @@
+package com.baeldung.returnfirstnonnull;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import java.util.Objects;
+import java.util.Optional;
+import java.util.function.Supplier;
+import java.util.stream.Stream;
+
+import org.apache.commons.lang3.ObjectUtils;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+public class ReturnFirstNonNullLazyEvaluateUnitTest {
+
+ private final LazyEvaluate spy = Mockito.spy(new LazyEvaluate());
+
+ @Test
+ void givenChainOfMethods_whenUsingIfStatements_thenLazilyEvaluateMethodsUntilFirstNonNull() {
+ String object = spy.methodA();
+ if (object == null) {
+ object = spy.methodB();
+ }
+
+ if (object == null) {
+ object = spy.methodC();
+ }
+
+ assertEquals("first non null", object);
+ verify(spy, times(1)).methodA();
+ verify(spy, times(1)).methodB();
+ verify(spy, times(0)).methodC();
+ }
+
+ @Test
+ void givenChainOfMethods_whenUsingApacheCommonsLang3_thenReturnFirstNonNull() {
+ String object = ObjectUtils.getFirstNonNull(spy::methodA, spy::methodB, spy::methodC);
+
+ assertEquals("first non null", object);
+ verify(spy, times(1)).methodA();
+ verify(spy, times(1)).methodB();
+ verify(spy, times(0)).methodC();
+ }
+
+ @Test
+ void givenChainOfMethods_whenUsingSupplierInterface_thenLazilyEvaluateMethodsUntilFirstNonNull() {
+ Optional object = Stream.> of(spy::methodA, spy::methodB, spy::methodC)
+ .map(Supplier::get)
+ .filter(Objects::nonNull)
+ .findFirst();
+
+ assertThat(object).contains("first non null");
+ verify(spy, times(1)).methodA();
+ verify(spy, times(1)).methodB();
+ verify(spy, times(0)).methodC();
+ }
+
+ @Test
+ void givenNonNullObjectAndFallbackMethod_whenUsingApacheCommonsLang3_thenReturnFirstNonNull() {
+ String nonNullObject = spy.methodB();
+ String object = ObjectUtils.getIfNull(nonNullObject, spy::methodC);
+
+ assertEquals("first non null", object);
+ verify(spy, times(0)).methodC();
+ }
+
+ @Test
+ void givenNullObjectAndFallbackMethod_whenUsingApacheCommonsLang3_thenReturnFirstNonNull() {
+ String nullObject = null;
+ String object = ObjectUtils.getIfNull(nullObject, spy::methodB);
+
+ assertEquals("first non null", object);
+ }
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-lang-6/src/test/java/com/baeldung/returnfirstnonnull/ReturnFirstNonNullUnitTest.java b/core-java-modules/core-java-lang-6/src/test/java/com/baeldung/returnfirstnonnull/ReturnFirstNonNullUnitTest.java
new file mode 100644
index 0000000000..124de5843c
--- /dev/null
+++ b/core-java-modules/core-java-lang-6/src/test/java/com/baeldung/returnfirstnonnull/ReturnFirstNonNullUnitTest.java
@@ -0,0 +1,81 @@
+package com.baeldung.returnfirstnonnull;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+
+import org.apache.commons.lang3.ObjectUtils;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Iterables;
+
+public class ReturnFirstNonNullUnitTest {
+
+ private List objects;
+
+ @BeforeEach
+ public void init() {
+ objects = Arrays.asList(null, "first non null", "second nun null");
+ }
+
+ @Test
+ void givenListOfObjects_whenFilterIsLambdaNullCheckInStream_thenReturnFirstNonNull() {
+ Optional object = objects.stream()
+ .filter(o -> o != null)
+ .findFirst();
+
+ assertThat(object).contains("first non null");
+ }
+
+ @Test
+ void givenListOfObjects_whenFilterIsMethodRefNullCheckInStream_thenReturnFirstNonNull() {
+ Optional object = objects.stream()
+ .filter(Objects::nonNull)
+ .findFirst();
+
+ assertThat(object).contains("first non null");
+ }
+
+ @Test
+ void givenListOfObjects_whenIteratingWithForLoop_thenReturnFirstNonNull() {
+ String object = null;
+ for (int i = 0; i < objects.size(); i++) {
+ if (objects.get(i) != null) {
+ object = objects.get(i);
+ break;
+ }
+ }
+
+ assertEquals("first non null", object);
+ }
+
+ @Test
+ void givenListOfObjects_whenUsingApacheCommonsLang3_thenReturnFirstNonNull() {
+ String object = ObjectUtils.firstNonNull(objects.toArray(new String[0]));
+
+ assertEquals("first non null", object);
+ }
+
+ @Test
+ void givenListOfObjects_whenUsingGoogleGuavaIterables_thenReturnFirstNonNull() {
+ String object = Iterables.find(objects, Predicates.notNull());
+
+ assertEquals("first non null", object);
+ }
+
+ @Test
+ void givenTwoObjects_whenUsingGoogleGuavaMoreObjects_thenReturnFirstNonNull() {
+ String nullObject = null;
+ String nonNullObject = "first non null";
+ String object = MoreObjects.firstNonNull(nullObject, nonNullObject);
+
+ assertEquals("first non null", object);
+ }
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Rectangle.java b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Rectangle.java
index 38f5edec61..ee43af3eff 100644
--- a/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Rectangle.java
+++ b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Rectangle.java
@@ -26,13 +26,25 @@ public class Rectangle {
this.topRight = topRight;
}
- public boolean isOverlapping(Rectangle other) {
- // one rectangle is to the top of the other
- if (this.topRight.getY() < other.bottomLeft.getY() || this.bottomLeft.getY() > other.topRight.getY()) {
+ public boolean isOverlapping(Rectangle comparedRectangle) {
+ // one rectangle is to the top of the comparedRectangle
+ if (this.topRight.getY() < comparedRectangle.bottomLeft.getY() || this.bottomLeft.getY() > comparedRectangle.topRight.getY()) {
return false;
}
- // one rectangle is to the left of the other
- if (this.topRight.getX() < other.bottomLeft.getX() || this.bottomLeft.getX() > other.topRight.getX()) {
+ // one rectangle is to the left of the comparedRectangle
+ if (this.topRight.getX() < comparedRectangle.bottomLeft.getX() || this.bottomLeft.getX() > comparedRectangle.topRight.getX()) {
+ return false;
+ }
+ return true;
+ }
+
+ public boolean isOverlappingWithoutBorders(Rectangle comparedRectangle) {
+ // one rectangle is to the top of the comparedRectangle
+ if (this.topRight.getY() <= comparedRectangle.bottomLeft.getY() || this.bottomLeft.getY() >= comparedRectangle.topRight.getY()) {
+ return false;
+ }
+ // one rectangle is to the left of the comparedRectangle
+ if (this.topRight.getX() <= comparedRectangle.bottomLeft.getX() || this.bottomLeft.getX() >= comparedRectangle.topRight.getX()) {
return false;
}
return true;
diff --git a/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/rectanglesoverlap/RectangleUnitTest.java b/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/rectanglesoverlap/RectangleUnitTest.java
index e4bb614b48..18186b43b1 100644
--- a/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/rectanglesoverlap/RectangleUnitTest.java
+++ b/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/rectanglesoverlap/RectangleUnitTest.java
@@ -1,7 +1,8 @@
package com.baeldung.algorithms.rectanglesoverlap;
-import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
import org.junit.Test;
public class RectangleUnitTest {
@@ -36,4 +37,18 @@ public class RectangleUnitTest {
assertFalse(rectangle1.isOverlapping(rectangle2));
}
+ @Test
+ public void givenAdjacentRectangles_whensOverlappingCalled_shouldReturnTrue() {
+Rectangle rectangle1 = new Rectangle(new Point(0, 0), new Point(5, 14));
+Rectangle rectangle2 = new Rectangle(new Point(5, 0), new Point(17, 14));
+assertTrue(rectangle1.isOverlapping(rectangle2));
+ }
+
+ @Test
+ public void givenAdjacentRectangles_whensOverlappingWithoutBordersCalled_shouldReturnFalse() {
+ Rectangle rectangle1 = new Rectangle(new Point(0, 0), new Point(5, 14));
+ Rectangle rectangle2 = new Rectangle(new Point(5, 0), new Point(17, 14));
+ assertFalse(rectangle1.isOverlappingWithoutBorders(rectangle2));
+ }
+
}
diff --git a/core-java-modules/core-java-lang-oop-methods/pom.xml b/core-java-modules/core-java-lang-oop-methods/pom.xml
index 6f246d78ce..5e53004d62 100644
--- a/core-java-modules/core-java-lang-oop-methods/pom.xml
+++ b/core-java-modules/core-java-lang-oop-methods/pom.xml
@@ -35,7 +35,7 @@
2.6
3.10.0
- 3.0.3
+ 3.15.3
\ No newline at end of file
diff --git a/core-java-modules/core-java-lang-oop-types-2/README.md b/core-java-modules/core-java-lang-oop-types-2/README.md
index f46a1a3306..208e3b7fa7 100644
--- a/core-java-modules/core-java-lang-oop-types-2/README.md
+++ b/core-java-modules/core-java-lang-oop-types-2/README.md
@@ -10,3 +10,4 @@ This module contains articles about types in Java
- [Filling a List With All Enum Values in Java](https://www.baeldung.com/java-enum-values-to-list)
- [Comparing a String to an Enum Value in Java](https://www.baeldung.com/java-comparing-string-to-enum)
- [Implementing toString() on enums in Java](https://www.baeldung.com/java-enums-tostring)
+- [Checking if an Object’s Type Is Enum](https://www.baeldung.com/java-check-object-enum)
diff --git a/core-java-modules/core-java-lang-oop-types-2/src/test/java/com/baeldung/enums/classcheck/CheckClassIsEnumUnitTest.java b/core-java-modules/core-java-lang-oop-types-2/src/test/java/com/baeldung/enums/classcheck/CheckClassIsEnumUnitTest.java
new file mode 100644
index 0000000000..a69df8739f
--- /dev/null
+++ b/core-java-modules/core-java-lang-oop-types-2/src/test/java/com/baeldung/enums/classcheck/CheckClassIsEnumUnitTest.java
@@ -0,0 +1,75 @@
+package com.baeldung.enums.classcheck;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+enum Device {
+ Keyboard, Monitor, Mouse, Printer
+}
+
+enum Weekday {
+ Monday, Tuesday, Wednesday, Thursday, Friday,
+ Saturday {
+ @Override
+ boolean isWeekend() {
+ return true;
+ }
+ },
+ Sunday {
+ @Override
+ boolean isWeekend() {
+ return true;
+ }
+ };
+
+ boolean isWeekend() {
+ return false;
+ }
+}
+
+public class CheckClassIsEnumUnitTest {
+
+ @Test
+ void whenUsingInstanceOf_thenGetExpectedResult() {
+ Object obj = Device.Keyboard;
+ assertTrue(obj instanceof Enum);
+ }
+
+ @Test
+ void whenUsingisInstance_thenGetExpectedResult() {
+ Object obj = Device.Keyboard;
+ assertTrue(Enum.class.isInstance(obj));
+ }
+
+ @Test
+ void whenUsingEnumClassisAssignableFrom_thenGetExpectedResult() {
+ Object obj = Device.Keyboard;
+ assertTrue(Enum.class.isAssignableFrom(obj.getClass()));
+ }
+
+ @Test
+ void whenUsingGetClassIsEnum_thenGetExpectedResult() {
+ assertTrue(Device.class.isEnum());
+
+ Object obj = Device.Keyboard;
+ assertTrue(obj.getClass().isEnum());
+ }
+
+
+ @Test
+ void whenEnum_thenGetExpectedResult() {
+ Object monday = Weekday.Monday;
+ assertTrue(monday instanceof Enum);
+ assertTrue(Enum.class.isInstance(monday));
+ assertTrue(Enum.class.isAssignableFrom(monday.getClass()));
+ assertTrue(monday.getClass().isEnum());
+
+ Object sunday = Weekday.Sunday;
+ assertTrue(sunday instanceof Enum);
+ assertTrue(Enum.class.isInstance(sunday));
+ assertTrue(Enum.class.isAssignableFrom(sunday.getClass()));
+ assertFalse(sunday.getClass().isEnum()); // <-- isEnum() check failed when Enum values with body
+ }
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-networking-4/pom.xml b/core-java-modules/core-java-networking-4/pom.xml
index cbe6356d0f..4b49359c8c 100644
--- a/core-java-modules/core-java-networking-4/pom.xml
+++ b/core-java-modules/core-java-networking-4/pom.xml
@@ -56,7 +56,7 @@
1.7
- 1.15.4
+ 1.16.2
\ No newline at end of file
diff --git a/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/negate/NegateIntUnitTest.java b/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/negate/NegateIntUnitTest.java
new file mode 100644
index 0000000000..444f4931d3
--- /dev/null
+++ b/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/negate/NegateIntUnitTest.java
@@ -0,0 +1,69 @@
+package com.baeldung.negate;
+
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+public class NegateIntUnitTest {
+
+ private static final Logger LOG = LoggerFactory.getLogger(NegateIntUnitTest.class);
+
+ @Test
+ void whenUsingUnaryMinusOperator_thenGetExpectedResult() {
+ int x = 42;
+ assertEquals(-42, -x);
+
+ int z = 0;
+ assertEquals(0, -z);
+
+ int n = -42;
+ assertEquals(42, -n);
+ }
+
+ @Test
+ void whenUsingBitwiseComplementOperator_thenGetExpectedResult() {
+ int x = 42;
+ assertEquals(-42, ~x + 1);
+
+ int z = 0;
+ assertEquals(0, ~z + 1);
+
+ int n = -42;
+ assertEquals(42, ~n + 1);
+ }
+
+ @Test
+ void givenIntMinValue_whenUsingUnaryMinusOperator_thenCannotGetExpectedResult() {
+ int min = Integer.MIN_VALUE;
+ LOG.info("The value of '-min' is: " + -min);
+
+ assertTrue((-min) < 0);
+ }
+
+ @Test
+ void givenIntMinValue_whenUsingBitwiseComplementOperator_thenCannotGetExpectedResult() {
+ int min = Integer.MIN_VALUE;
+ int result = ~min + 1;
+ LOG.info("The value of '~min + 1' is: " + result);
+
+ assertTrue(result < 0);
+ }
+
+
+ @Test
+ void whenUsingUnaryMinusOperatorWithMinInt_thenGetExpectedResult() {
+ int x = 42;
+ assertEquals(-42, Math.negateExact(x));
+
+ int z = 0;
+ assertEquals(0, Math.negateExact(z));
+
+ int n = -42;
+ assertEquals(42, Math.negateExact(n));
+
+ int min = Integer.MIN_VALUE;
+ assertThrowsExactly(ArithmeticException.class, () -> Math.negateExact(min));
+ }
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-serialization/pom.xml b/core-java-modules/core-java-serialization/pom.xml
index 63771d2da0..ad0a730514 100644
--- a/core-java-modules/core-java-serialization/pom.xml
+++ b/core-java-modules/core-java-serialization/pom.xml
@@ -177,7 +177,7 @@
0.4
1.8.7
1.1
- 3.0.0-M1
+ 3.6.2
4.3.20.RELEASE
diff --git a/core-java-modules/core-java-string-operations-7/README.md b/core-java-modules/core-java-string-operations-7/README.md
index 2b9c4c25f3..a05485ccb9 100644
--- a/core-java-modules/core-java-string-operations-7/README.md
+++ b/core-java-modules/core-java-string-operations-7/README.md
@@ -5,3 +5,4 @@
- [Check if a String Contains Only Unicode Letters](https://www.baeldung.com/java-string-all-unicode-characters)
- [Create a Mutable String in Java](https://www.baeldung.com/java-mutable-string)
- [Check if a String Contains a Number Value in Java](https://www.baeldung.com/java-string-number-presence)
+- [Difference Between String isEmpty() and isBlank()](https://www.baeldung.com/java-string-isempty-vs-isblank)
diff --git a/core-java-modules/core-java-string-operations-7/pom.xml b/core-java-modules/core-java-string-operations-7/pom.xml
index a2c7036e34..33a74365bc 100644
--- a/core-java-modules/core-java-string-operations-7/pom.xml
+++ b/core-java-modules/core-java-string-operations-7/pom.xml
@@ -24,12 +24,6 @@
commons-text
${commons-text.version}
-
- org.liquibase
- liquibase-core
- 4.9.1
- test
-
org.junit.jupiter
junit-jupiter
@@ -39,7 +33,7 @@
org.liquibase
liquibase-core
- 4.9.1
+ ${liquibase.core.version}
test
@@ -67,6 +61,7 @@
11
3.13.0
1.10.0
+ 4.25.0
\ No newline at end of file
diff --git a/core-java-modules/core-java-string-operations-7/src/test/java/com/baeldung/centertext/CenteringTextUnitTest.java b/core-java-modules/core-java-string-operations-7/src/test/java/com/baeldung/centertext/CenteringTextUnitTest.java
index a3f95b0181..408d7b1a63 100644
--- a/core-java-modules/core-java-string-operations-7/src/test/java/com/baeldung/centertext/CenteringTextUnitTest.java
+++ b/core-java-modules/core-java-string-operations-7/src/test/java/com/baeldung/centertext/CenteringTextUnitTest.java
@@ -1,6 +1,6 @@
package com.baeldung.centertext;
-import liquibase.repackaged.org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.StringUtils;
import org.junit.Assert;
import org.junit.jupiter.api.Test;
diff --git a/core-java-modules/core-java-string-operations-7/src/test/java/com/baeldung/isemptyvsisblank/StringIsEmptyVsIsBlankUnitTest.java b/core-java-modules/core-java-string-operations-7/src/test/java/com/baeldung/isemptyvsisblank/StringIsEmptyVsIsBlankUnitTest.java
new file mode 100644
index 0000000000..f6950237c5
--- /dev/null
+++ b/core-java-modules/core-java-string-operations-7/src/test/java/com/baeldung/isemptyvsisblank/StringIsEmptyVsIsBlankUnitTest.java
@@ -0,0 +1,25 @@
+package com.baeldung.isemptyvsisblank;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class StringIsEmptyVsIsBlankUnitTest {
+
+ @Test
+ public void givenString_whenCallIsEmpty_thenReturnCorrectValues() {
+ assertFalse("Example text".isEmpty());
+ assertTrue("".isEmpty());
+ assertFalse(" ".isEmpty());
+ assertFalse("\t\n\r\f".isEmpty());
+ }
+
+ @Test
+ public void givenString_whenCallStringIsBlank_thenReturnCorrectValues() {
+ assertFalse("Example text".isBlank());
+ assertTrue("".isBlank());
+ assertTrue(" ".isBlank());
+ assertTrue("\t\n\r\f ".isBlank());
+ }
+}
diff --git a/core-java-modules/core-java-strings/src/main/java/com/baeldung/stringbuffer/ComparePerformance.java b/core-java-modules/core-java-strings/src/main/java/com/baeldung/stringbuffer/ComparePerformance.java
new file mode 100644
index 0000000000..28cd2e64e9
--- /dev/null
+++ b/core-java-modules/core-java-strings/src/main/java/com/baeldung/stringbuffer/ComparePerformance.java
@@ -0,0 +1,63 @@
+package com.baeldung.stringbuffer;
+
+import java.util.concurrent.TimeUnit;
+
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Measurement;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.Warmup;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.RunnerException;
+import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+
+@BenchmarkMode(Mode.SingleShotTime)
+@OutputTimeUnit(TimeUnit.MILLISECONDS)
+@Measurement(batchSize = 10000, iterations = 10)
+@Warmup(batchSize = 1000, iterations = 10)
+@State(Scope.Thread)
+public class ComparePerformance {
+
+ String strInitial = "springframework";
+ String strFinal = "";
+ String replacement = "java-";
+
+ @Benchmark
+ public String benchmarkStringConcatenation() {
+ strFinal += strInitial;
+ return strFinal;
+ }
+
+ @Benchmark
+ public StringBuffer benchmarkStringBufferConcatenation() {
+ StringBuffer stringBuffer = new StringBuffer(strFinal);
+ stringBuffer.append(strInitial);
+ return stringBuffer;
+ }
+
+ @Benchmark
+ public String benchmarkStringReplacement() {
+ strFinal = strInitial.replaceFirst("spring", replacement);
+ return strFinal;
+ }
+
+ @Benchmark
+ public StringBuffer benchmarkStringBufferReplacement() {
+ StringBuffer stringBuffer = new StringBuffer(strInitial);
+ stringBuffer.replace(0,6, replacement);
+ return stringBuffer;
+ }
+
+ public static void main(String[] args) throws RunnerException {
+ Options options = new OptionsBuilder()
+ .include(ComparePerformance.class.getSimpleName()).threads(1)
+ .forks(1).shouldFailOnError(true)
+ .shouldDoGC(true)
+ .jvmArgs("-server").build();
+ new Runner(options).run();
+ }
+}
diff --git a/core-java-modules/core-java-strings/src/main/java/com/baeldung/stringbuffer/HashCode.java b/core-java-modules/core-java-strings/src/main/java/com/baeldung/stringbuffer/HashCode.java
new file mode 100644
index 0000000000..65f17263a9
--- /dev/null
+++ b/core-java-modules/core-java-strings/src/main/java/com/baeldung/stringbuffer/HashCode.java
@@ -0,0 +1,24 @@
+package com.baeldung.stringbuffer;
+
+public class HashCode {
+
+ public static long getHashCodeString(String string) {
+ return string.hashCode();
+ }
+
+ public static long getHashCodeSBuffer(StringBuffer strBuff) {
+ return strBuff.hashCode();
+ }
+
+ public static void main(String[] args) {
+ String str = "Spring";
+ System.out.println("String HashCode pre concatenation :" + getHashCodeString(str));
+ str += "Framework";
+ System.out.println("String HashCode post concatenation :" + getHashCodeString(str));
+
+ StringBuffer sBuf = new StringBuffer("Spring");
+ System.out.println("StringBuffer HashCode pre concatenation :" + getHashCodeSBuffer(sBuf));
+ sBuf.append("Framework");
+ System.out.println("StringBuffer HashCode post concatenation :" + getHashCodeSBuffer(sBuf));
+ }
+}
diff --git a/core-java-modules/core-java-strings/src/test/java/com/baeldung/stringIterator/StringIteratorTest.java b/core-java-modules/core-java-strings/src/test/java/com/baeldung/stringIterator/StringIteratorTest.java
index 585d65d4be..aef7f81da2 100644
--- a/core-java-modules/core-java-strings/src/test/java/com/baeldung/stringIterator/StringIteratorTest.java
+++ b/core-java-modules/core-java-strings/src/test/java/com/baeldung/stringIterator/StringIteratorTest.java
@@ -17,7 +17,7 @@ public class StringIteratorTest {
public void whenUseJavaForLoop_thenIterate() {
String input = "Hello, Baeldung!";
String expectedOutput = "Hello, Baeldung!";
- String result = StringIterator.javaForLoop(input);
+ String result = StringIterator.javaforLoop(input);
assertEquals(expectedOutput, result);
}
@@ -25,7 +25,7 @@ public class StringIteratorTest {
public void whenUseForEachMethod_thenIterate() {
String input = "Hello, Baeldung!";
String expectedOutput = "Hello, Baeldung!";
- String result = StringIterator.java8ForEach(input);
+ String result = StringIterator.java8forEach(input);
assertEquals(expectedOutput, result);
}
diff --git a/core-java-modules/core-java-strings/src/test/java/com/baeldung/stringbuffer/ComparePerformanceTest.java b/core-java-modules/core-java-strings/src/test/java/com/baeldung/stringbuffer/ComparePerformanceTest.java
new file mode 100644
index 0000000000..696c4bae6b
--- /dev/null
+++ b/core-java-modules/core-java-strings/src/test/java/com/baeldung/stringbuffer/ComparePerformanceTest.java
@@ -0,0 +1,32 @@
+package com.baeldung.stringbuffer;
+
+import org.junit.Test;
+import static org.assertj.core.api.Assertions.assertThat;
+
+
+public class ComparePerformanceTest {
+
+ ComparePerformance cp = new ComparePerformance();
+
+ @Test
+ public void whenStringConcatenated_thenResultAsExpected() {
+ assertThat(cp.benchmarkStringConcatenation()).isEqualTo("springframework");
+ }
+
+ @Test
+ public void whenStringBufferConcatenated_thenResultAsExpected() {
+ StringBuffer stringBuffer = new StringBuffer("springframework");
+ assertThat(cp.benchmarkStringBufferConcatenation()).isEqualToIgnoringCase(stringBuffer);
+ }
+
+ @Test
+ public void whenStringReplaced_thenResultAsExpected() {
+ assertThat(cp.benchmarkStringReplacement()).isEqualTo("java-framework");
+ }
+
+ @Test
+ public void whenStringBufferReplaced_thenResultAsExpected() {
+ StringBuffer stringBuffer = new StringBuffer("java-framework");
+ assertThat(cp.benchmarkStringBufferReplacement()).isEqualToIgnoringCase(stringBuffer);
+ }
+}
diff --git a/core-java-modules/core-java-strings/src/test/java/com/baeldung/stringbuffer/HashCodeTest.java b/core-java-modules/core-java-strings/src/test/java/com/baeldung/stringbuffer/HashCodeTest.java
new file mode 100644
index 0000000000..265c4e1e40
--- /dev/null
+++ b/core-java-modules/core-java-strings/src/test/java/com/baeldung/stringbuffer/HashCodeTest.java
@@ -0,0 +1,24 @@
+package com.baeldung.stringbuffer;
+
+import org.junit.Test;
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class HashCodeTest {
+
+ String str = "Spring";
+ StringBuffer sBuf = new StringBuffer("Spring");
+
+ @Test
+ public void whenStringConcat_thenHashCodeChanges() {
+ HashCode hc = new HashCode();
+
+ long initialStringHashCode = hc.getHashCodeString(str);
+ long initialSBufHashCode = hc.getHashCodeSBuffer(sBuf);
+
+ str += "Framework";
+ sBuf.append("Framework");
+
+ assertThat(initialStringHashCode).isNotEqualTo(hc.getHashCodeString(str));
+ assertThat(initialSBufHashCode).isEqualTo(hc.getHashCodeSBuffer(sBuf));
+ }
+}
diff --git a/core-java-modules/core-java-swing/pom.xml b/core-java-modules/core-java-swing/pom.xml
new file mode 100644
index 0000000000..28228ebb29
--- /dev/null
+++ b/core-java-modules/core-java-swing/pom.xml
@@ -0,0 +1,21 @@
+
+
+ 4.0.0
+ core-java-string-swing
+ core-java-string-swing
+ jar
+
+
+ com.baeldung.core-java-modules
+ core-java-modules
+ 0.0.1-SNAPSHOT
+
+
+ 20
+ 20
+ UTF-8
+
+
+
\ No newline at end of file
diff --git a/core-java-modules/core-java-swing/src/main/java/com/baeldung/customfont/CustomFonts.java b/core-java-modules/core-java-swing/src/main/java/com/baeldung/customfont/CustomFonts.java
new file mode 100644
index 0000000000..28e0da84ae
--- /dev/null
+++ b/core-java-modules/core-java-swing/src/main/java/com/baeldung/customfont/CustomFonts.java
@@ -0,0 +1,55 @@
+package com.baeldung.customfont;
+
+import javax.swing.*;
+import java.awt.*;
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+
+public class CustomFonts {
+ public static void main(String[] args) {
+ usingCustomFonts();
+ }
+
+ public static void usingCustomFonts() {
+ final GraphicsEnvironment GE = GraphicsEnvironment.getLocalGraphicsEnvironment();
+ final List AVAILABLE_FONT_FAMILY_NAMES = Arrays.asList(GE.getAvailableFontFamilyNames());
+ try {
+ final List LIST = Arrays.asList(
+ new File("font/JetBrainsMono/JetBrainsMono-Thin.ttf"),
+ new File("font/JetBrainsMono/JetBrainsMono-Light.ttf"),
+ new File("font/Roboto/Roboto-Light.ttf"),
+ new File("font/Roboto/Roboto-Regular.ttf"),
+ new File("font/Roboto/Roboto-Medium.ttf")
+ );
+ for (File LIST_ITEM : LIST) {
+ if (LIST_ITEM.exists()) {
+ Font FONT = Font.createFont(Font.TRUETYPE_FONT, LIST_ITEM);
+ if (!AVAILABLE_FONT_FAMILY_NAMES.contains(FONT.getFontName())) {
+ GE.registerFont(FONT);
+ }
+ }
+ }
+ } catch (FontFormatException | IOException exception) {
+ JOptionPane.showMessageDialog(null, exception.getMessage());
+ }
+
+
+ JFrame frame = new JFrame("Custom Font Example");
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ frame.setLayout(new FlowLayout());
+
+ JLabel label1 = new JLabel("TEXT1");
+ label1.setFont(new Font("Roboto Medium", Font.PLAIN, 17));
+
+ JLabel label2 = new JLabel("TEXT2");
+ label2.setFont(new Font("JetBrainsMono-Thin", Font.PLAIN, 17));
+
+ frame.add(label1);
+ frame.add(label2);
+
+ frame.pack();
+ frame.setVisible(true);
+ }
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-swing/target/classes/org/example/Main.class b/core-java-modules/core-java-swing/target/classes/org/example/Main.class
new file mode 100644
index 0000000000..5914458bc4
Binary files /dev/null and b/core-java-modules/core-java-swing/target/classes/org/example/Main.class differ
diff --git a/core-java-modules/core-java-uuid/pom.xml b/core-java-modules/core-java-uuid/pom.xml
index d46fcd8a65..0a0835ca46 100644
--- a/core-java-modules/core-java-uuid/pom.xml
+++ b/core-java-modules/core-java-uuid/pom.xml
@@ -154,7 +154,7 @@
- 3.0.0-M1
+ 3.6.2
diff --git a/core-java-modules/core-java-uuid/src/main/java/com/baeldung/uuid/UUIDPositiveLongGenerator.java b/core-java-modules/core-java-uuid/src/main/java/com/baeldung/uuid/UUIDPositiveLongGenerator.java
new file mode 100644
index 0000000000..eb3a511256
--- /dev/null
+++ b/core-java-modules/core-java-uuid/src/main/java/com/baeldung/uuid/UUIDPositiveLongGenerator.java
@@ -0,0 +1,83 @@
+package com.baeldung.uuid;
+
+import java.nio.ByteBuffer;
+import java.security.SecureRandom;
+import java.util.UUID;
+
+/**
+ * Methods are called by reflection in the unit test
+ */
+@SuppressWarnings("unused")
+public class UUIDPositiveLongGenerator {
+ public long getLeastSignificantBits() {
+ return Math.abs(UUID.randomUUID().getLeastSignificantBits());
+ }
+
+ public long getMostSignificantBits() {
+ return Math.abs(UUID.randomUUID().getMostSignificantBits());
+ }
+
+ public long combineByteBuffer() {
+ UUID uuid = UUID.randomUUID();
+ ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
+ bb.putLong(uuid.getMostSignificantBits());
+ bb.putLong(uuid.getLeastSignificantBits());
+ bb.rewind();
+ return Math.abs(bb.getLong());
+ }
+
+ public long combineBitwise() {
+ UUID uniqueUUID = UUID.randomUUID();
+ long mostSignificantBits = uniqueUUID.getMostSignificantBits();
+ long leastSignificantBits = uniqueUUID.getLeastSignificantBits();
+ return Math.abs((mostSignificantBits << 32) | (leastSignificantBits & 0xFFFFFFFFL));
+ }
+
+ public long combineDirect() {
+ UUID uniqueUUID = UUID.randomUUID();
+ long mostSignificantBits = uniqueUUID.getMostSignificantBits();
+ long leastSignificantBits = uniqueUUID.getLeastSignificantBits();
+ return Math.abs(mostSignificantBits ^ (leastSignificantBits >> 1));
+ }
+
+ public long combinePermutation() {
+ UUID uuid = UUID.randomUUID();
+ long mostSigBits = uuid.getMostSignificantBits();
+ long leastSigBits = uuid.getLeastSignificantBits();
+ byte[] uuidBytes = new byte[16];
+
+ for (int i = 0; i < 8; i++) {
+ uuidBytes[i] = (byte) (mostSigBits >>> (8 * (7 - i)));
+ uuidBytes[i + 8] = (byte) (leastSigBits >>> (8 * (7 - i)));
+ }
+
+ long result = 0;
+ for (byte b : uuidBytes) {
+ result = (result << 8) | (b & 0xFF);
+ }
+ return Math.abs(result);
+ }
+
+ public long combineWithSecureRandom() {
+ UUID uniqueUUID = UUID.randomUUID();
+ SecureRandom secureRandom = new SecureRandom();
+ long randomBits = secureRandom.nextLong();
+
+ long mostSignificantBits = uniqueUUID.getMostSignificantBits() ^ randomBits;
+ long leastSignificantBits = uniqueUUID.getLeastSignificantBits();
+
+ return Math.abs((mostSignificantBits << 32) | (leastSignificantBits & 0xFFFFFFFFL));
+ }
+
+ public long combineWithNanoTime() {
+ UUID uniqueUUID = UUID.randomUUID();
+ long nanoTime = System.nanoTime();
+
+ long mostSignificantBits = uniqueUUID.getMostSignificantBits() ^ nanoTime;
+ long leastSignificantBits = uniqueUUID.getLeastSignificantBits();
+
+ return Math.abs((mostSignificantBits << 32) | (leastSignificantBits & 0xFFFFFFFFL));
+ }
+
+
+}
diff --git a/core-java-modules/core-java-uuid/src/test/java/com/baeldung/uuid/UUIDPositiveLongGeneratorUnitTest.java b/core-java-modules/core-java-uuid/src/test/java/com/baeldung/uuid/UUIDPositiveLongGeneratorUnitTest.java
new file mode 100644
index 0000000000..a4d57b19c2
--- /dev/null
+++ b/core-java-modules/core-java-uuid/src/test/java/com/baeldung/uuid/UUIDPositiveLongGeneratorUnitTest.java
@@ -0,0 +1,43 @@
+package com.baeldung.uuid;
+
+import org.junit.jupiter.api.Test;
+
+import java.lang.reflect.Method;
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class UUIDPositiveLongGeneratorUnitTest {
+
+ private final UUIDPositiveLongGenerator uuidLongGenerator = new UUIDPositiveLongGenerator();
+
+ private final Set uniqueValues = new HashSet<>();
+
+ @Test
+ void whenForeachMethods_thenRetryWhileNotUnique() throws Exception {
+ for (Method method : uuidLongGenerator.getClass().getDeclaredMethods()) {
+ long uniqueValue;
+ do uniqueValue = (long) method.invoke(uuidLongGenerator); while (!isUnique(uniqueValue));
+ assertThat(uniqueValue).isPositive();
+ }
+ }
+
+ @Test
+ void whenGivenLongValue_thenCheckUniqueness() {
+ long uniqueValue = generateUniqueLong();
+ assertThat(uniqueValue).isPositive();
+ }
+
+ private long generateUniqueLong() {
+ long uniqueValue;
+ do uniqueValue = uuidLongGenerator.combineBitwise(); while (!isUnique(uniqueValue));
+ return uniqueValue;
+ }
+
+ private boolean isUnique(long value) {
+ // Implement uniqueness checking logic, for example, by checking in the database
+ return uniqueValues.add(value);
+ }
+
+}
diff --git a/core-java-modules/core-java-uuid/src/test/resources/logback.xml b/core-java-modules/core-java-uuid/src/test/resources/logback.xml
index 56af2d397e..a076f8db47 100644
--- a/core-java-modules/core-java-uuid/src/test/resources/logback.xml
+++ b/core-java-modules/core-java-uuid/src/test/resources/logback.xml
@@ -2,8 +2,7 @@
- %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
-
+ %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml
index a237fe0ed6..b3ef8167a5 100644
--- a/core-java-modules/pom.xml
+++ b/core-java-modules/pom.xml
@@ -54,6 +54,7 @@
core-java-concurrency-simple
core-java-datetime-string
core-java-io-conversions-2
+ core-java-ipc
core-java-jpms
core-java-lang-oop-constructors-2
core-java-methods
@@ -183,6 +184,7 @@
core-java-string-algorithms
core-java-string-algorithms-2
core-java-string-apis
+ core-java-swing
core-java-string-apis-2
core-java-string-conversions
core-java-string-conversions-2
@@ -198,7 +200,8 @@
core-java-records
core-java-9-jigsaw
-
+
+
core-java-collections-set
core-java-date-operations-1
core-java-datetime-conversion
diff --git a/feign/pom.xml b/feign/pom.xml
index edb55e7da5..127f6c490c 100644
--- a/feign/pom.xml
+++ b/feign/pom.xml
@@ -74,6 +74,17 @@
${wire.mock.version}
test
+
+ jakarta.xml.bind
+ jakarta.xml.bind-api
+ 4.0.0
+
+
+ com.sun.xml.bind
+ jaxb-impl
+ 4.0.0
+ runtime
+
@@ -85,7 +96,7 @@
org.codehaus.mojo
jaxb2-maven-plugin
- 2.5.0
+ 3.1.0
xjc
@@ -131,6 +142,7 @@
3.8.0
3.1.2
2.33.2
+ 4.0.0
\ No newline at end of file
diff --git a/gradle-modules/gradle-7/gradle-proxy-configuration/.gitignore b/gradle-modules/gradle-7/gradle-proxy-configuration/.gitignore
new file mode 100644
index 0000000000..b63da4551b
--- /dev/null
+++ b/gradle-modules/gradle-7/gradle-proxy-configuration/.gitignore
@@ -0,0 +1,42 @@
+.gradle
+build/
+!gradle/wrapper/gradle-wrapper.jar
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### IntelliJ IDEA ###
+.idea/modules.xml
+.idea/jarRepositories.xml
+.idea/compiler.xml
+.idea/libraries/
+*.iws
+*.iml
+*.ipr
+out/
+!**/src/main/**/out/
+!**/src/test/**/out/
+
+### Eclipse ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+bin/
+!**/src/main/**/bin/
+!**/src/test/**/bin/
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+
+### VS Code ###
+.vscode/
+
+### Mac OS ###
+.DS_Store
\ No newline at end of file
diff --git a/gradle-modules/gradle-7/gradle-proxy-configuration/build.gradle b/gradle-modules/gradle-7/gradle-proxy-configuration/build.gradle
new file mode 100644
index 0000000000..7463486961
--- /dev/null
+++ b/gradle-modules/gradle-7/gradle-proxy-configuration/build.gradle
@@ -0,0 +1,20 @@
+plugins {
+ id 'java'
+}
+
+group = 'org.baeldung'
+version = '1.0-SNAPSHOT'
+
+repositories {
+ mavenCentral()
+}
+
+dependencies {
+ testImplementation platform('org.junit:junit-bom:5.9.1')
+ testImplementation 'org.junit.jupiter:junit-jupiter'
+ implementation 'io.micrometer:micrometer-core:1.12.0'
+}
+
+test {
+ useJUnitPlatform()
+}
\ No newline at end of file
diff --git a/gradle-modules/gradle-7/gradle-proxy-configuration/gradle.properties b/gradle-modules/gradle-7/gradle-proxy-configuration/gradle.properties
new file mode 100644
index 0000000000..207872023f
--- /dev/null
+++ b/gradle-modules/gradle-7/gradle-proxy-configuration/gradle.properties
@@ -0,0 +1,12 @@
+# HTTP proxy settings
+systemProp.http.proxyHost=localhost
+systemProp.http.proxyPort=3128
+systemProp.http.proxyUser=USER
+systemProp.http.proxyPassword=PASSWORD
+systemProp.http.nonProxyHosts=*.nonproxyrepos.com
+# HTTPS proxy settings
+systemProp.https.proxyHost=localhost
+systemProp.https.proxyPort=3128
+systemProp.https.proxyUser=USER
+systemProp.https.proxyPassword=PASSWORD
+systemProp.https.nonProxyHosts=*.nonproxyrepos.com
\ No newline at end of file
diff --git a/gradle-modules/gradle-7/gradle-proxy-configuration/gradle/wrapper/gradle-wrapper.jar b/gradle-modules/gradle-7/gradle-proxy-configuration/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000000..249e5832f0
Binary files /dev/null and b/gradle-modules/gradle-7/gradle-proxy-configuration/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle-modules/gradle-7/gradle-proxy-configuration/gradle/wrapper/gradle-wrapper.properties b/gradle-modules/gradle-7/gradle-proxy-configuration/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000000..cc09a557e8
--- /dev/null
+++ b/gradle-modules/gradle-7/gradle-proxy-configuration/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Thu Nov 16 23:15:01 GMT 2023
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStorePath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
diff --git a/gradle-modules/gradle-7/gradle-proxy-configuration/gradlew b/gradle-modules/gradle-7/gradle-proxy-configuration/gradlew
new file mode 100755
index 0000000000..1b6c787337
--- /dev/null
+++ b/gradle-modules/gradle-7/gradle-proxy-configuration/gradlew
@@ -0,0 +1,234 @@
+#!/bin/sh
+
+#
+# Copyright © 2015-2021 the original authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+##############################################################################
+#
+# Gradle start up script for POSIX generated by Gradle.
+#
+# Important for running:
+#
+# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
+# noncompliant, but you have some other compliant shell such as ksh or
+# bash, then to run this script, type that shell name before the whole
+# command line, like:
+#
+# ksh Gradle
+#
+# Busybox and similar reduced shells will NOT work, because this script
+# requires all of these POSIX shell features:
+# * functions;
+# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
+# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
+# * compound commands having a testable exit status, especially «case»;
+# * various built-in commands including «command», «set», and «ulimit».
+#
+# Important for patching:
+#
+# (2) This script targets any POSIX shell, so it avoids extensions provided
+# by Bash, Ksh, etc; in particular arrays are avoided.
+#
+# The "traditional" practice of packing multiple parameters into a
+# space-separated string is a well documented source of bugs and security
+# problems, so this is (mostly) avoided, by progressively accumulating
+# options in "$@", and eventually passing that to Java.
+#
+# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
+# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
+# see the in-line comments for details.
+#
+# There are tweaks for specific operating systems such as AIX, CygWin,
+# Darwin, MinGW, and NonStop.
+#
+# (3) This script is generated from the Groovy template
+# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
+# within the Gradle project.
+#
+# You can find Gradle at https://github.com/gradle/gradle/.
+#
+##############################################################################
+
+# Attempt to set APP_HOME
+
+# Resolve links: $0 may be a link
+app_path=$0
+
+# Need this for daisy-chained symlinks.
+while
+ APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
+ [ -h "$app_path" ]
+do
+ ls=$( ls -ld "$app_path" )
+ link=${ls#*' -> '}
+ case $link in #(
+ /*) app_path=$link ;; #(
+ *) app_path=$APP_HOME$link ;;
+ esac
+done
+
+APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
+
+APP_NAME="Gradle"
+APP_BASE_NAME=${0##*/}
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD=maximum
+
+warn () {
+ echo "$*"
+} >&2
+
+die () {
+ echo
+ echo "$*"
+ echo
+ exit 1
+} >&2
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "$( uname )" in #(
+ CYGWIN* ) cygwin=true ;; #(
+ Darwin* ) darwin=true ;; #(
+ MSYS* | MINGW* ) msys=true ;; #(
+ NONSTOP* ) nonstop=true ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD=$JAVA_HOME/jre/sh/java
+ else
+ JAVACMD=$JAVA_HOME/bin/java
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD=java
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
+ case $MAX_FD in #(
+ max*)
+ MAX_FD=$( ulimit -H -n ) ||
+ warn "Could not query maximum file descriptor limit"
+ esac
+ case $MAX_FD in #(
+ '' | soft) :;; #(
+ *)
+ ulimit -n "$MAX_FD" ||
+ warn "Could not set maximum file descriptor limit to $MAX_FD"
+ esac
+fi
+
+# Collect all arguments for the java command, stacking in reverse order:
+# * args from the command line
+# * the main class name
+# * -classpath
+# * -D...appname settings
+# * --module-path (only if needed)
+# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
+
+# For Cygwin or MSYS, switch paths to Windows format before running java
+if "$cygwin" || "$msys" ; then
+ APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
+ CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
+
+ JAVACMD=$( cygpath --unix "$JAVACMD" )
+
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ for arg do
+ if
+ case $arg in #(
+ -*) false ;; # don't mess with options #(
+ /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
+ [ -e "$t" ] ;; #(
+ *) false ;;
+ esac
+ then
+ arg=$( cygpath --path --ignore --mixed "$arg" )
+ fi
+ # Roll the args list around exactly as many times as the number of
+ # args, so each arg winds up back in the position where it started, but
+ # possibly modified.
+ #
+ # NB: a `for` loop captures its iteration list before it begins, so
+ # changing the positional parameters here affects neither the number of
+ # iterations, nor the values presented in `arg`.
+ shift # remove old arg
+ set -- "$@" "$arg" # push replacement arg
+ done
+fi
+
+# Collect all arguments for the java command;
+# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
+# shell script including quotes and variable substitutions, so put them in
+# double quotes to make sure that they get re-expanded; and
+# * put everything else in single quotes, so that it's not re-expanded.
+
+set -- \
+ "-Dorg.gradle.appname=$APP_BASE_NAME" \
+ -classpath "$CLASSPATH" \
+ org.gradle.wrapper.GradleWrapperMain \
+ "$@"
+
+# Use "xargs" to parse quoted args.
+#
+# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
+#
+# In Bash we could simply go:
+#
+# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
+# set -- "${ARGS[@]}" "$@"
+#
+# but POSIX shell has neither arrays nor command substitution, so instead we
+# post-process each arg (as a line of input to sed) to backslash-escape any
+# character that might be a shell metacharacter, then use eval to reverse
+# that process (while maintaining the separation between arguments), and wrap
+# the whole thing up as a single "set" statement.
+#
+# This will of course break if any of these variables contains a newline or
+# an unmatched quote.
+#
+
+eval "set -- $(
+ printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
+ xargs -n1 |
+ sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
+ tr '\n' ' '
+ )" '"$@"'
+
+exec "$JAVACMD" "$@"
diff --git a/gradle-modules/gradle-7/gradle-proxy-configuration/gradlew.bat b/gradle-modules/gradle-7/gradle-proxy-configuration/gradlew.bat
new file mode 100644
index 0000000000..ac1b06f938
--- /dev/null
+++ b/gradle-modules/gradle-7/gradle-proxy-configuration/gradlew.bat
@@ -0,0 +1,89 @@
+@rem
+@rem Copyright 2015 the original author or authors.
+@rem
+@rem Licensed under the Apache License, Version 2.0 (the "License");
+@rem you may not use this file except in compliance with the License.
+@rem You may obtain a copy of the License at
+@rem
+@rem https://www.apache.org/licenses/LICENSE-2.0
+@rem
+@rem Unless required by applicable law or agreed to in writing, software
+@rem distributed under the License is distributed on an "AS IS" BASIS,
+@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@rem See the License for the specific language governing permissions and
+@rem limitations under the License.
+@rem
+
+@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 Resolve any "." and ".." in APP_HOME to make it shorter.
+for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
+
+@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="-Xmx64m" "-Xms64m"
+
+@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 execute
+
+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 execute
+
+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
+
+: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 %*
+
+: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/gradle-modules/gradle-7/gradle-proxy-configuration/settings.gradle b/gradle-modules/gradle-7/gradle-proxy-configuration/settings.gradle
new file mode 100644
index 0000000000..02edde146a
--- /dev/null
+++ b/gradle-modules/gradle-7/gradle-proxy-configuration/settings.gradle
@@ -0,0 +1,2 @@
+rootProject.name = 'gradle-proxy-configuration'
+
diff --git a/java-spi/exchange-rate-impl/pom.xml b/java-spi/exchange-rate-impl/pom.xml
index 254a8bb809..7ec10b1c04 100644
--- a/java-spi/exchange-rate-impl/pom.xml
+++ b/java-spi/exchange-rate-impl/pom.xml
@@ -65,7 +65,7 @@
1.0.0-SNAPSHOT
- 3.10.0
+ 4.12.0
1.0
1.0.1
1.1.2
diff --git a/javaxval-2/pom.xml b/javaxval-2/pom.xml
index f73f23bcb2..366fd9fdbf 100644
--- a/javaxval-2/pom.xml
+++ b/javaxval-2/pom.xml
@@ -9,26 +9,24 @@
com.baeldung
- parent-modules
- 1.0.0-SNAPSHOT
+ parent-boot-3
+ 0.0.1-SNAPSHOT
+ ../parent-boot-3
org.springframework.boot
spring-boot-starter-validation
- ${spring.boot.version}
org.springframework.boot
spring-boot-starter-test
- ${spring.boot.version}
test
com.fasterxml.jackson.core
jackson-databind
- ${jackson.databind.version}
@@ -42,9 +40,16 @@
-
- 3.0.4
- 2.14.0
-
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+ true
+
+
+
+
\ No newline at end of file
diff --git a/javaxval-2/src/test/java/com/baeldung/javaxval/afterdeserialization/StudentDeserializerWithValidationUnitTest.java b/javaxval-2/src/test/java/com/baeldung/javaxval/afterdeserialization/StudentDeserializerWithValidationUnitTest.java
index 094236e963..8c3761ae09 100644
--- a/javaxval-2/src/test/java/com/baeldung/javaxval/afterdeserialization/StudentDeserializerWithValidationUnitTest.java
+++ b/javaxval-2/src/test/java/com/baeldung/javaxval/afterdeserialization/StudentDeserializerWithValidationUnitTest.java
@@ -1,4 +1,4 @@
-package com.baeldung.javaxval;
+package com.baeldung.javaxval.afterdeserialization;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
diff --git a/javaxval/pom.xml b/javaxval/pom.xml
index c4a30f915d..e1a3dc350c 100644
--- a/javaxval/pom.xml
+++ b/javaxval/pom.xml
@@ -8,20 +8,19 @@
com.baeldung
- parent-modules
- 1.0.0-SNAPSHOT
+ parent-boot-3
+ 0.0.1-SNAPSHOT
+ ../parent-boot-3
org.springframework.boot
spring-boot-starter-validation
- ${spring.boot.version}
org.springframework.boot
spring-boot-starter-test
- ${spring.boot.version}
test
@@ -38,7 +37,6 @@
8.0.1.Final
- 3.0.4
\ No newline at end of file
diff --git a/jmeter/src/main/java/com/baeldung/configuration/WebSecurityConfiguration.java b/jmeter/src/main/java/com/baeldung/configuration/WebSecurityConfiguration.java
index 8700dc3df4..033281e07f 100644
--- a/jmeter/src/main/java/com/baeldung/configuration/WebSecurityConfiguration.java
+++ b/jmeter/src/main/java/com/baeldung/configuration/WebSecurityConfiguration.java
@@ -1,52 +1,44 @@
package com.baeldung.configuration;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
-import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+import org.springframework.security.core.userdetails.User;
+import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
import org.springframework.security.crypto.password.PasswordEncoder;
+import org.springframework.security.provisioning.InMemoryUserDetailsManager;
+import org.springframework.security.web.SecurityFilterChain;
@Configuration
-public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
+public class WebSecurityConfiguration {
- @Override
- protected void configure(AuthenticationManagerBuilder auth) throws Exception {
-
+ @Bean
+ public InMemoryUserDetailsManager userDetailsService() {
PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
-
- auth.inMemoryAuthentication()
- .withUser("admin").password(encoder.encode("admin")).roles("USER", "ADMIN")
- .and()
- .withUser("user1").password(encoder.encode("password1")).roles("USER")
- .and()
- .withUser("user2").password(encoder.encode("password2")).roles("USER")
- .and()
- .withUser("user3").password(encoder.encode("password3")).roles("USER")
- .and()
- .withUser("user4").password(encoder.encode("password4")).roles("USER")
- .and()
- .withUser("user5").password(encoder.encode("password5")).roles("USER")
- .and()
- .withUser("user6").password(encoder.encode("password6")).roles("USER")
- .and()
- .withUser("user7").password(encoder.encode("password7")).roles("USER")
- .and()
- .withUser("user8").password(encoder.encode("password8")).roles("USER")
- .and()
- .withUser("user9").password(encoder.encode("password9")).roles("USER")
- .and()
- .withUser("user10").password(encoder.encode("password10")).roles("USER");
+
+ Set users = new HashSet<>();
+ users.add(User.withUsername("admin").password(encoder.encode("admin")).roles("USER", "ADMIN").build());
+ for(int i=1;i<=10;i++){
+ users.add(User.withUsername("user"+i).password(encoder.encode("password")+i).roles("USER").build());
+ }
+
+ return new InMemoryUserDetailsManager(users);
}
- @Override
- protected void configure(HttpSecurity http) throws Exception {
-
+ @Bean
+ public SecurityFilterChain securityFilter(HttpSecurity http) throws Exception {
+
http
.authorizeRequests()
.antMatchers("/secured/**").authenticated()
.anyRequest().permitAll()
.and()
.httpBasic();
+
+ return http.build();
}
}
diff --git a/json-modules/gson-2/src/main/java/com/baeldung/gson/multiplefields/BasicStudent.java b/json-modules/gson-2/src/main/java/com/baeldung/gson/multiplefields/BasicStudent.java
new file mode 100644
index 0000000000..9c8d5f0923
--- /dev/null
+++ b/json-modules/gson-2/src/main/java/com/baeldung/gson/multiplefields/BasicStudent.java
@@ -0,0 +1,64 @@
+package com.baeldung.gson.multiplefields;
+
+import java.util.Objects;
+
+import com.google.gson.annotations.SerializedName;
+
+public class BasicStudent {
+
+ private String name;
+
+ private transient String major;
+
+ @SerializedName("major")
+ private String concentration;
+
+ public BasicStudent() {
+
+ }
+
+ public BasicStudent(String name, String major, String concentration) {
+ this.name = name;
+ this.major = major;
+ this.concentration = concentration;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (!(o instanceof BasicStudent))
+ return false;
+ BasicStudent student = (BasicStudent) o;
+ return Objects.equals(name, student.name) && Objects.equals(major, student.major) && Objects.equals(concentration, student.concentration);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(name, major, concentration);
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getMajor() {
+ return major;
+ }
+
+ public void setMajor(String major) {
+ this.major = major;
+ }
+
+ public String getConcentration() {
+ return concentration;
+ }
+
+ public void setConcentration(String concentration) {
+ this.concentration = concentration;
+ }
+}
diff --git a/json-modules/gson-2/src/main/java/com/baeldung/gson/multiplefields/StudentExclusionStrategy.java b/json-modules/gson-2/src/main/java/com/baeldung/gson/multiplefields/StudentExclusionStrategy.java
new file mode 100644
index 0000000000..5dad30a138
--- /dev/null
+++ b/json-modules/gson-2/src/main/java/com/baeldung/gson/multiplefields/StudentExclusionStrategy.java
@@ -0,0 +1,18 @@
+package com.baeldung.gson.multiplefields;
+
+import com.google.gson.ExclusionStrategy;
+import com.google.gson.FieldAttributes;
+
+public class StudentExclusionStrategy implements ExclusionStrategy {
+
+ @Override
+ public boolean shouldSkipField(FieldAttributes field) {
+ // Ignore all field values from V1 type
+ return field.getDeclaringClass() == StudentV1.class;
+ }
+
+ @Override
+ public boolean shouldSkipClass(Class> aClass) {
+ return false;
+ }
+}
diff --git a/json-modules/gson-2/src/main/java/com/baeldung/gson/multiplefields/StudentV1.java b/json-modules/gson-2/src/main/java/com/baeldung/gson/multiplefields/StudentV1.java
new file mode 100644
index 0000000000..49a09b830c
--- /dev/null
+++ b/json-modules/gson-2/src/main/java/com/baeldung/gson/multiplefields/StudentV1.java
@@ -0,0 +1,34 @@
+package com.baeldung.gson.multiplefields;
+
+public class StudentV1 {
+
+ private String firstName;
+ private String lastName;
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ // Default constructor for Gson
+ public StudentV1() {
+
+ }
+
+ public StudentV1(String firstName, String lastName) {
+ this.firstName = firstName;
+ this.lastName = lastName;
+ }
+
+}
diff --git a/json-modules/gson-2/src/main/java/com/baeldung/gson/multiplefields/StudentV2.java b/json-modules/gson-2/src/main/java/com/baeldung/gson/multiplefields/StudentV2.java
new file mode 100644
index 0000000000..e31d33e3fd
--- /dev/null
+++ b/json-modules/gson-2/src/main/java/com/baeldung/gson/multiplefields/StudentV2.java
@@ -0,0 +1,71 @@
+package com.baeldung.gson.multiplefields;
+
+import java.util.Objects;
+
+import com.google.gson.annotations.Expose;
+
+public class StudentV2 extends StudentV1 {
+
+ @Expose
+ private String firstName;
+
+ @Expose
+ private String lastName;
+
+ @Expose
+ private String major;
+
+ @Override
+ public String getFirstName() {
+ return firstName;
+ }
+
+ @Override
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ @Override
+ public String getLastName() {
+ return lastName;
+ }
+
+ @Override
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ public String getMajor() {
+ return major;
+ }
+
+ public void setMajor(String major) {
+ this.major = major;
+ }
+
+ // Default constructor for Gson
+ public StudentV2() {
+
+ }
+
+ public StudentV2(String firstName, String lastName, String major) {
+ this.firstName = firstName;
+ this.lastName = lastName;
+ this.major = major;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (!(o instanceof StudentV2))
+ return false;
+ StudentV2 studentV2 = (StudentV2) o;
+ return Objects.equals(firstName, studentV2.firstName) && Objects.equals(lastName, studentV2.lastName) && Objects.equals(major, studentV2.major);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(firstName, lastName, major);
+ }
+}
diff --git a/json-modules/gson-2/src/test/java/com/baeldung/gson/multiplefields/GsonMultipleFieldsUnitTest.java b/json-modules/gson-2/src/test/java/com/baeldung/gson/multiplefields/GsonMultipleFieldsUnitTest.java
new file mode 100644
index 0000000000..1ee2cd1bd8
--- /dev/null
+++ b/json-modules/gson-2/src/test/java/com/baeldung/gson/multiplefields/GsonMultipleFieldsUnitTest.java
@@ -0,0 +1,65 @@
+package com.baeldung.gson.multiplefields;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.junit.Test;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+public class GsonMultipleFieldsUnitTest {
+
+ @Test
+ public void givenBasicStudent_whenSerializingWithGson_thenTransientFieldNotSet() {
+ // Given a class with a transient field
+ BasicStudent student = new BasicStudent("Henry Winter", "Greek Studies", "Classical Greek Studies");
+
+ // When serializing using Gson
+ Gson gson = new Gson();
+ String json = gson.toJson(student);
+
+ // Then the deserialized instance doesn't contain the transient field value
+ BasicStudent deserialized = gson.fromJson(json, BasicStudent.class);
+ assertThat(deserialized.getMajor()).isNull();
+ }
+
+ @Test
+ public void givenStudentV2_whenSerializingWithGson_thenIllegalArgumentExceptionIsThrown() {
+ // Given a class with a class hierarchy that defines multiple fields with the same name
+ StudentV2 student = new StudentV2("Henry", "Winter", "Greek Studies");
+
+ // When serializing using Gson, then an IllegalArgumentException exception is thrown
+ Gson gson = new Gson();
+ assertThatThrownBy(() -> gson.toJson(student)).isInstanceOf(IllegalArgumentException.class)
+ .hasMessageContaining("declares multiple JSON fields named 'firstName'");
+ }
+
+ @Test
+ public void givenStudentV2_whenSerializingWithGsonExposeAnnotation_thenSerializes() {
+ // Given a class with a class hierarchy that defines multiple fields with the same name
+ StudentV2 student = new StudentV2("Henry", "Winter", "Greek Studies");
+
+ // When serializing using Gson exclude fields without @Expose
+ Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation()
+ .create();
+
+ // Then ensure the student can be serialized, then deserialized back into an equal instance
+ String json = gson.toJson(student);
+ assertThat(gson.fromJson(json, StudentV2.class)).isEqualTo(student);
+ }
+
+ @Test
+ public void givenStudentV2_whenSerializingWithGsonExclusionStrategy_thenSerializes() {
+ // Given a class with a class hierarchy that defines multiple fields with the same name
+ StudentV2 student = new StudentV2("Henry", "Winter", "Greek Studies");
+
+ // When serializing using Gson add an ExclusionStrategy
+ Gson gson = new GsonBuilder().setExclusionStrategies(new StudentExclusionStrategy())
+ .create();
+
+ // Then ensure the student can be serialized, then deserialized back into an equal instance
+ assertThat(gson.fromJson(gson.toJson(student), StudentV2.class)).isEqualTo(student);
+ }
+
+}
\ No newline at end of file
diff --git a/jsoup/pom.xml b/jsoup/pom.xml
index 44f8f996f5..d2780424de 100644
--- a/jsoup/pom.xml
+++ b/jsoup/pom.xml
@@ -22,7 +22,7 @@
- 1.10.2
+ 1.16.2
\ No newline at end of file
diff --git a/jsoup/src/test/java/com/baeldung/jsoup/PreservingLineBreaksUnitTest.java b/jsoup/src/test/java/com/baeldung/jsoup/PreservingLineBreaksUnitTest.java
index 0958fa96e2..e6bd8eccbf 100644
--- a/jsoup/src/test/java/com/baeldung/jsoup/PreservingLineBreaksUnitTest.java
+++ b/jsoup/src/test/java/com/baeldung/jsoup/PreservingLineBreaksUnitTest.java
@@ -2,7 +2,7 @@ package com.baeldung.jsoup;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
-import org.jsoup.safety.Whitelist;
+import org.jsoup.safety.Safelist;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@@ -13,7 +13,7 @@ public class PreservingLineBreaksUnitTest {
String strHTML = "Hello\nworld";
Document.OutputSettings outputSettings = new Document.OutputSettings();
outputSettings.prettyPrint(false);
- String strWithNewLines = Jsoup.clean(strHTML, "", Whitelist.none(), outputSettings);
+ String strWithNewLines = Jsoup.clean(strHTML, "", Safelist.none(), outputSettings);
assertEquals("Hello\nworld", strWithNewLines);
}
@@ -33,7 +33,7 @@ public class PreservingLineBreaksUnitTest {
jsoupDoc.select("p").before("\\n");
String str = jsoupDoc.html().replaceAll("\\\\n", "\n");
String strWithNewLines =
- Jsoup.clean(str, "", Whitelist.none(), outputSettings);
+ Jsoup.clean(str, "", Safelist.none(), outputSettings);
assertEquals("Hello\nWorld\nParagraph", strWithNewLines);
}
}
diff --git a/libraries-6/pom.xml b/libraries-6/pom.xml
index 9fa44d3a32..f073ca424c 100644
--- a/libraries-6/pom.xml
+++ b/libraries-6/pom.xml
@@ -197,7 +197,7 @@
1.10.0
2.7.1
4.8.1
- 0.12.1
+ 2.1.0
1.15
3.6
3.5-beta72
diff --git a/libraries-6/src/test/java/com/baeldung/resilence4j/Resilience4jUnitTest.java b/libraries-6/src/test/java/com/baeldung/resilence4j/Resilience4jUnitTest.java
index 1d69d20bc2..ab4d9dde40 100644
--- a/libraries-6/src/test/java/com/baeldung/resilence4j/Resilience4jUnitTest.java
+++ b/libraries-6/src/test/java/com/baeldung/resilence4j/Resilience4jUnitTest.java
@@ -43,7 +43,7 @@ public class Resilience4jUnitTest {
// Percentage of failures to start short-circuit
.failureRateThreshold(20)
// Min number of call attempts
- .ringBufferSizeInClosedState(5)
+ .slidingWindowSize(5)
.build();
CircuitBreakerRegistry registry = CircuitBreakerRegistry.of(config);
CircuitBreaker circuitBreaker = registry.circuitBreaker("my");
@@ -70,7 +70,7 @@ public class Resilience4jUnitTest {
Future> taskInProgress = callAndBlock(decorated);
try {
- assertThat(bulkhead.isCallPermitted()).isFalse();
+ assertThat(bulkhead.tryAcquirePermission()).isFalse();
} finally {
taskInProgress.cancel(true);
}
diff --git a/libraries-http-2/pom.xml b/libraries-http-2/pom.xml
index c80c5729a7..b49e4b9387 100644
--- a/libraries-http-2/pom.xml
+++ b/libraries-http-2/pom.xml
@@ -109,7 +109,7 @@
- 4.9.1
+ 4.12.0
2.10.1
4.9.1
1.0.3
diff --git a/libraries-http/pom.xml b/libraries-http/pom.xml
index c726b56b5d..caf42639cc 100644
--- a/libraries-http/pom.xml
+++ b/libraries-http/pom.xml
@@ -105,7 +105,7 @@
2.10.1
4.5.3
- 4.9.1
+ 4.12.0
1.23.0
2.2.0
2.3.0
diff --git a/osgi/pom.xml b/osgi/pom.xml
index ecc8758ef9..16b1f5d106 100644
--- a/osgi/pom.xml
+++ b/osgi/pom.xml
@@ -91,7 +91,7 @@
- 3.9.0
+ 4.12.0
1.1
6.0.0
3.3.0
diff --git a/pdf/pom.xml b/pdf/pom.xml
index 0fe90b6eb5..041f356b9a 100644
--- a/pdf/pom.xml
+++ b/pdf/pom.xml
@@ -111,12 +111,12 @@
3.15
1.8
3.15
- 3.0.11.RELEASE
- 9.1.20
+ 3.1.2.RELEASE
+ 9.3.1
1.0.6
- 1.0.6
- 9.1.22
- 1.14.2
+ 1.0.10
+ 9.2.1
+ 1.16.2
\ No newline at end of file
diff --git a/performance-tests/pom.xml b/performance-tests/pom.xml
index d22a9cf3ac..7927c518f9 100644
--- a/performance-tests/pom.xml
+++ b/performance-tests/pom.xml
@@ -164,7 +164,7 @@
3.2.4
3.0.0-M1
3.2.0
- 3.2.0
+ 3.6.2
3.1.0
3.9.1
3.2.1
diff --git a/atomikos/README.md b/persistence-modules/atomikos/README.md
similarity index 100%
rename from atomikos/README.md
rename to persistence-modules/atomikos/README.md
diff --git a/atomikos/pom.xml b/persistence-modules/atomikos/pom.xml
similarity index 98%
rename from atomikos/pom.xml
rename to persistence-modules/atomikos/pom.xml
index 2cbc106268..c1748f7dac 100644
--- a/atomikos/pom.xml
+++ b/persistence-modules/atomikos/pom.xml
@@ -8,7 +8,7 @@
com.baeldung
- parent-modules
+ persistence-modules
1.0.0-SNAPSHOT
diff --git a/atomikos/src/main/java/com/baeldung/atomikos/direct/Application.java b/persistence-modules/atomikos/src/main/java/com/baeldung/atomikos/direct/Application.java
similarity index 100%
rename from atomikos/src/main/java/com/baeldung/atomikos/direct/Application.java
rename to persistence-modules/atomikos/src/main/java/com/baeldung/atomikos/direct/Application.java
diff --git a/atomikos/src/main/java/com/baeldung/atomikos/spring/Application.java b/persistence-modules/atomikos/src/main/java/com/baeldung/atomikos/spring/Application.java
similarity index 100%
rename from atomikos/src/main/java/com/baeldung/atomikos/spring/Application.java
rename to persistence-modules/atomikos/src/main/java/com/baeldung/atomikos/spring/Application.java
diff --git a/atomikos/src/main/java/com/baeldung/atomikos/spring/config/Config.java b/persistence-modules/atomikos/src/main/java/com/baeldung/atomikos/spring/config/Config.java
similarity index 100%
rename from atomikos/src/main/java/com/baeldung/atomikos/spring/config/Config.java
rename to persistence-modules/atomikos/src/main/java/com/baeldung/atomikos/spring/config/Config.java
diff --git a/atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/Application.java b/persistence-modules/atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/Application.java
similarity index 100%
rename from atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/Application.java
rename to persistence-modules/atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/Application.java
diff --git a/atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/config/Config.java b/persistence-modules/atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/config/Config.java
similarity index 100%
rename from atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/config/Config.java
rename to persistence-modules/atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/config/Config.java
diff --git a/atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/inventory/Inventory.java b/persistence-modules/atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/inventory/Inventory.java
similarity index 100%
rename from atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/inventory/Inventory.java
rename to persistence-modules/atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/inventory/Inventory.java
diff --git a/atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/inventory/InventoryConfig.java b/persistence-modules/atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/inventory/InventoryConfig.java
similarity index 100%
rename from atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/inventory/InventoryConfig.java
rename to persistence-modules/atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/inventory/InventoryConfig.java
diff --git a/atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/inventory/InventoryRepository.java b/persistence-modules/atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/inventory/InventoryRepository.java
similarity index 100%
rename from atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/inventory/InventoryRepository.java
rename to persistence-modules/atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/inventory/InventoryRepository.java
diff --git a/atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/order/Order.java b/persistence-modules/atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/order/Order.java
similarity index 100%
rename from atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/order/Order.java
rename to persistence-modules/atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/order/Order.java
diff --git a/atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/order/OrderConfig.java b/persistence-modules/atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/order/OrderConfig.java
similarity index 100%
rename from atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/order/OrderConfig.java
rename to persistence-modules/atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/order/OrderConfig.java
diff --git a/atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/order/OrderRepository.java b/persistence-modules/atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/order/OrderRepository.java
similarity index 100%
rename from atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/order/OrderRepository.java
rename to persistence-modules/atomikos/src/main/java/com/baeldung/atomikos/spring/jpa/order/OrderRepository.java
diff --git a/atomikos/src/main/resources/logback.xml b/persistence-modules/atomikos/src/main/resources/logback.xml
similarity index 100%
rename from atomikos/src/main/resources/logback.xml
rename to persistence-modules/atomikos/src/main/resources/logback.xml
diff --git a/atomikos/src/main/resources/schema.sql b/persistence-modules/atomikos/src/main/resources/schema.sql
similarity index 100%
rename from atomikos/src/main/resources/schema.sql
rename to persistence-modules/atomikos/src/main/resources/schema.sql
diff --git a/atomikos/src/main/resources/transactions.properties b/persistence-modules/atomikos/src/main/resources/transactions.properties
similarity index 100%
rename from atomikos/src/main/resources/transactions.properties
rename to persistence-modules/atomikos/src/main/resources/transactions.properties
diff --git a/atomikos/src/test/java/com/baeldung/atomikos/direct/ApplicationUnitTest.java b/persistence-modules/atomikos/src/test/java/com/baeldung/atomikos/direct/ApplicationUnitTest.java
similarity index 100%
rename from atomikos/src/test/java/com/baeldung/atomikos/direct/ApplicationUnitTest.java
rename to persistence-modules/atomikos/src/test/java/com/baeldung/atomikos/direct/ApplicationUnitTest.java
diff --git a/atomikos/src/test/java/com/baeldung/atomikos/spring/ApplicationUnitTest.java b/persistence-modules/atomikos/src/test/java/com/baeldung/atomikos/spring/ApplicationUnitTest.java
similarity index 100%
rename from atomikos/src/test/java/com/baeldung/atomikos/spring/ApplicationUnitTest.java
rename to persistence-modules/atomikos/src/test/java/com/baeldung/atomikos/spring/ApplicationUnitTest.java
diff --git a/atomikos/src/test/java/com/baeldung/atomikos/spring/jpa/ApplicationUnitTest.java b/persistence-modules/atomikos/src/test/java/com/baeldung/atomikos/spring/jpa/ApplicationUnitTest.java
similarity index 100%
rename from atomikos/src/test/java/com/baeldung/atomikos/spring/jpa/ApplicationUnitTest.java
rename to persistence-modules/atomikos/src/test/java/com/baeldung/atomikos/spring/jpa/ApplicationUnitTest.java
diff --git a/atomikos/src/test/resources/logback.xml b/persistence-modules/atomikos/src/test/resources/logback.xml
similarity index 100%
rename from atomikos/src/test/resources/logback.xml
rename to persistence-modules/atomikos/src/test/resources/logback.xml
diff --git a/atomikos/src/test/resources/transactions.properties b/persistence-modules/atomikos/src/test/resources/transactions.properties
similarity index 100%
rename from atomikos/src/test/resources/transactions.properties
rename to persistence-modules/atomikos/src/test/resources/transactions.properties
diff --git a/persistence-modules/hibernate-libraries/pom.xml b/persistence-modules/hibernate-libraries/pom.xml
index 5b1879b78e..3fa15ffb0b 100644
--- a/persistence-modules/hibernate-libraries/pom.xml
+++ b/persistence-modules/hibernate-libraries/pom.xml
@@ -162,7 +162,7 @@
1.6
2.9.7
- 5.4.14.Final
+ 5.6.15.Final
3.27.0-GA
2.3.1
2.0.0
diff --git a/persistence-modules/liquibase/pom.xml b/persistence-modules/liquibase/pom.xml
index 90397aec4d..a6e0ed85e9 100644
--- a/persistence-modules/liquibase/pom.xml
+++ b/persistence-modules/liquibase/pom.xml
@@ -37,7 +37,7 @@
8.2.0
- 3.4.2
+ 4.25.0
\ No newline at end of file
diff --git a/persistence-modules/pom.xml b/persistence-modules/pom.xml
index 6823b460b2..d9ee7e358c 100644
--- a/persistence-modules/pom.xml
+++ b/persistence-modules/pom.xml
@@ -18,6 +18,7 @@
apache-bookkeeper
apache-cayenne
apache-derby
+ atomikos
blaze-persistence
core-java-persistence
core-java-persistence-2
diff --git a/persistence-modules/spring-data-jpa-enterprise-2/README.md b/persistence-modules/spring-data-jpa-enterprise-2/README.md
index 9bb08cc497..8e154f6b75 100644
--- a/persistence-modules/spring-data-jpa-enterprise-2/README.md
+++ b/persistence-modules/spring-data-jpa-enterprise-2/README.md
@@ -4,8 +4,7 @@ This module contains articles about Spring Data JPA used in enterprise applicati
### Relevant Articles:
-- [Spring JPA – Multiple Databases](https://www.baeldung.com/spring-data-jpa-multiple-databases)
-- [Pagination and Sorting using Spring Data JPA](https://www.baeldung.com/spring-data-jpa-pagination-sorting)
+
### Eclipse Config
After importing the project into Eclipse, you may see the following error:
diff --git a/persistence-modules/spring-data-jpa-enterprise/README.md b/persistence-modules/spring-data-jpa-enterprise/README.md
index d1039dcc50..b563fa46d4 100644
--- a/persistence-modules/spring-data-jpa-enterprise/README.md
+++ b/persistence-modules/spring-data-jpa-enterprise/README.md
@@ -11,6 +11,8 @@ This module contains articles about Spring Data JPA used in enterprise applicati
- [Custom Naming Convention with Spring Data JPA](https://www.baeldung.com/spring-data-jpa-custom-naming)
- [Partial Data Update With Spring Data](https://www.baeldung.com/spring-data-partial-update)
- [Spring Data JPA @Modifying Annotation](https://www.baeldung.com/spring-data-jpa-modifying-annotation)
+- [Spring JPA – Multiple Databases](https://www.baeldung.com/spring-data-jpa-multiple-databases)
+- [Pagination and Sorting using Spring Data JPA](https://www.baeldung.com/spring-data-jpa-pagination-sorting)
### Eclipse Config
After importing the project into Eclipse, you may see the following error:
diff --git a/persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/multipledb/MultipleDbApplication.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/MultipleDbApplication.java
similarity index 100%
rename from persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/multipledb/MultipleDbApplication.java
rename to persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/MultipleDbApplication.java
diff --git a/persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/multipledb/PersistenceProductAutoConfiguration.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/PersistenceProductAutoConfiguration.java
similarity index 100%
rename from persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/multipledb/PersistenceProductAutoConfiguration.java
rename to persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/PersistenceProductAutoConfiguration.java
diff --git a/persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/multipledb/PersistenceProductConfiguration.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/PersistenceProductConfiguration.java
similarity index 99%
rename from persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/multipledb/PersistenceProductConfiguration.java
rename to persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/PersistenceProductConfiguration.java
index bcf2cd84eb..da974e979a 100644
--- a/persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/multipledb/PersistenceProductConfiguration.java
+++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/PersistenceProductConfiguration.java
@@ -1,6 +1,9 @@
package com.baeldung.multipledb;
-import com.google.common.base.Preconditions;
+import java.util.HashMap;
+
+import javax.sql.DataSource;
+
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -14,8 +17,7 @@ import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;
-import javax.sql.DataSource;
-import java.util.HashMap;
+import com.google.common.base.Preconditions;
@Configuration
@PropertySource({"classpath:persistence-multiple-db.properties"})
diff --git a/persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/multipledb/PersistenceUserAutoConfiguration.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/PersistenceUserAutoConfiguration.java
similarity index 100%
rename from persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/multipledb/PersistenceUserAutoConfiguration.java
rename to persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/PersistenceUserAutoConfiguration.java
diff --git a/persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/multipledb/PersistenceUserConfiguration.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/PersistenceUserConfiguration.java
similarity index 90%
rename from persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/multipledb/PersistenceUserConfiguration.java
rename to persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/PersistenceUserConfiguration.java
index 6b48455c0c..ca5d6f9c7a 100644
--- a/persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/multipledb/PersistenceUserConfiguration.java
+++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/PersistenceUserConfiguration.java
@@ -1,8 +1,15 @@
package com.baeldung.multipledb;
-import com.google.common.base.Preconditions;
+import java.util.HashMap;
+
+import javax.sql.DataSource;
+
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.*;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Primary;
+import org.springframework.context.annotation.Profile;
+import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
@@ -11,8 +18,7 @@ import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;
-import javax.sql.DataSource;
-import java.util.HashMap;
+import com.google.common.base.Preconditions;
@Configuration
@PropertySource({"classpath:persistence-multiple-db.properties"})
diff --git a/persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/multipledb/dao/product/ProductRepository.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/dao/product/ProductRepository.java
similarity index 100%
rename from persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/multipledb/dao/product/ProductRepository.java
rename to persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/dao/product/ProductRepository.java
diff --git a/persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/multipledb/dao/user/PossessionRepository.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/dao/user/PossessionRepository.java
similarity index 100%
rename from persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/multipledb/dao/user/PossessionRepository.java
rename to persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/dao/user/PossessionRepository.java
diff --git a/persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/multipledb/dao/user/UserRepository.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/dao/user/UserRepository.java
similarity index 100%
rename from persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/multipledb/dao/user/UserRepository.java
rename to persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/dao/user/UserRepository.java
diff --git a/persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/multipledb/model/product/Product.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/model/product/Product.java
similarity index 100%
rename from persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/multipledb/model/product/Product.java
rename to persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/model/product/Product.java
diff --git a/persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/multipledb/model/user/Possession.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/model/user/Possession.java
similarity index 90%
rename from persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/multipledb/model/user/Possession.java
rename to persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/model/user/Possession.java
index af646ffd04..c9bd3c42bc 100644
--- a/persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/multipledb/model/user/Possession.java
+++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/model/user/Possession.java
@@ -1,6 +1,10 @@
package com.baeldung.multipledb.model.user;
-import javax.persistence.*;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
@Entity
@Table
diff --git a/persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/multipledb/model/user/User.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/model/user/User.java
similarity index 87%
rename from persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/multipledb/model/user/User.java
rename to persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/model/user/User.java
index 1985c543d3..224eefc3ff 100644
--- a/persistence-modules/spring-data-jpa-enterprise-2/src/main/java/com/baeldung/multipledb/model/user/User.java
+++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/model/user/User.java
@@ -1,9 +1,15 @@
package com.baeldung.multipledb.model.user;
-import javax.persistence.*;
-
import java.util.List;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+
@Entity
@Table(name = "users")
public class User {
diff --git a/persistence-modules/spring-data-jpa-enterprise-2/src/main/resources/persistence-multiple-db-boot.properties b/persistence-modules/spring-data-jpa-enterprise/src/main/resources/persistence-multiple-db-boot.properties
similarity index 100%
rename from persistence-modules/spring-data-jpa-enterprise-2/src/main/resources/persistence-multiple-db-boot.properties
rename to persistence-modules/spring-data-jpa-enterprise/src/main/resources/persistence-multiple-db-boot.properties
diff --git a/persistence-modules/spring-data-jpa-enterprise-2/src/main/resources/persistence-multiple-db.properties b/persistence-modules/spring-data-jpa-enterprise/src/main/resources/persistence-multiple-db.properties
similarity index 100%
rename from persistence-modules/spring-data-jpa-enterprise-2/src/main/resources/persistence-multiple-db.properties
rename to persistence-modules/spring-data-jpa-enterprise/src/main/resources/persistence-multiple-db.properties
diff --git a/persistence-modules/spring-data-jpa-enterprise-2/src/test/java/com/baeldung/multipledb/JpaMultipleDBIntegrationTest.java b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/multipledb/JpaMultipleDBIntegrationTest.java
similarity index 100%
rename from persistence-modules/spring-data-jpa-enterprise-2/src/test/java/com/baeldung/multipledb/JpaMultipleDBIntegrationTest.java
rename to persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/multipledb/JpaMultipleDBIntegrationTest.java
diff --git a/persistence-modules/spring-data-jpa-enterprise-2/src/test/java/com/baeldung/multipledb/ProductRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/multipledb/ProductRepositoryIntegrationTest.java
similarity index 100%
rename from persistence-modules/spring-data-jpa-enterprise-2/src/test/java/com/baeldung/multipledb/ProductRepositoryIntegrationTest.java
rename to persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/multipledb/ProductRepositoryIntegrationTest.java
diff --git a/persistence-modules/spring-data-jpa-repo-2/README.md b/persistence-modules/spring-data-jpa-repo-2/README.md
index 23134ec02d..8c588405f7 100644
--- a/persistence-modules/spring-data-jpa-repo-2/README.md
+++ b/persistence-modules/spring-data-jpa-repo-2/README.md
@@ -2,9 +2,7 @@
### Relevant Articles:
-- [Introduction to Spring Data JPA](https://www.baeldung.com/the-persistence-layer-with-spring-data-jpa)
- [Performance Difference Between save() and saveAll() in Spring Data](https://www.baeldung.com/spring-data-save-saveall)
-- [LIKE Queries in Spring JPA Repositories](https://www.baeldung.com/spring-jpa-like-queries)
- [How to Access EntityManager with Spring Data](https://www.baeldung.com/spring-data-entitymanager)
- [Difference Between JPA and Spring Data JPA](https://www.baeldung.com/spring-data-jpa-vs-jpa)
- [Differences Between Spring Data JPA findFirst() and findTop()](https://www.baeldung.com/spring-data-jpa-findfirst-vs-findtop)
diff --git a/persistence-modules/spring-data-jpa-repo-2/pom.xml b/persistence-modules/spring-data-jpa-repo-2/pom.xml
index 8186a0f7a5..e39458449c 100644
--- a/persistence-modules/spring-data-jpa-repo-2/pom.xml
+++ b/persistence-modules/spring-data-jpa-repo-2/pom.xml
@@ -42,11 +42,6 @@
com.querydsl
querydsl-jpa
-
- com.google.guava
- guava
- ${guava.version}
-
diff --git a/persistence-modules/spring-data-jpa-repo-2/src/test/resources/test-movie-cleanup.sql b/persistence-modules/spring-data-jpa-repo-2/src/test/resources/test-movie-cleanup.sql
deleted file mode 100644
index 0ba0ba0694..0000000000
--- a/persistence-modules/spring-data-jpa-repo-2/src/test/resources/test-movie-cleanup.sql
+++ /dev/null
@@ -1 +0,0 @@
-DELETE FROM "movie";
\ No newline at end of file
diff --git a/persistence-modules/spring-data-jpa-repo-2/src/test/resources/test-movie-data.sql b/persistence-modules/spring-data-jpa-repo-2/src/test/resources/test-movie-data.sql
deleted file mode 100644
index 0eb9638f43..0000000000
--- a/persistence-modules/spring-data-jpa-repo-2/src/test/resources/test-movie-data.sql
+++ /dev/null
@@ -1,7 +0,0 @@
-INSERT INTO "movie" ("id", "title", "director", "rating", "duration") VALUES(1, 'Godzilla: King of the Monsters', ' Michael Dougherty', 'PG-13', 132);
-INSERT INTO "movie" ("id", "title", "director", "rating", "duration") VALUES(2, 'Avengers: Endgame', 'Anthony Russo', 'PG-13', 181);
-INSERT INTO "movie" ("id", "title", "director", "rating", "duration") VALUES(3, 'Captain Marvel', 'Anna Boden', 'PG-13', 123);
-INSERT INTO "movie" ("id", "title", "director", "rating", "duration") VALUES(4, 'Dumbo', 'Tim Burton', 'PG', 112);
-INSERT INTO "movie" ("id", "title", "director", "rating", "duration") VALUES(5, 'Booksmart', 'Olivia Wilde', 'R', 102);
-INSERT INTO "movie" ("id", "title", "director", "rating", "duration") VALUES(6, 'Aladdin', 'Guy Ritchie', 'PG', 128);
-INSERT INTO "movie" ("id", "title", "director", "rating", "duration") VALUES(7, 'The Sun Is Also a Star', 'Ry Russo-Young', 'PG-13', 100);
diff --git a/persistence-modules/spring-data-jpa-repo/README.md b/persistence-modules/spring-data-jpa-repo/README.md
index 43097a8c1e..9587f544f9 100644
--- a/persistence-modules/spring-data-jpa-repo/README.md
+++ b/persistence-modules/spring-data-jpa-repo/README.md
@@ -3,6 +3,7 @@
This module contains articles about repositories in Spring Data JPA
### Relevant Articles:
+- [Introduction to Spring Data JPA](https://www.baeldung.com/the-persistence-layer-with-spring-data-jpa)
- [Case Insensitive Queries with Spring Data Repository](https://www.baeldung.com/spring-data-case-insensitive-queries)
- [Derived Query Methods in Spring Data JPA Repositories](https://www.baeldung.com/spring-data-derived-queries)
- [Spring Data – CrudRepository save() Method](https://www.baeldung.com/spring-data-crud-repository-save)
@@ -10,6 +11,8 @@ This module contains articles about repositories in Spring Data JPA
- [Spring Data Composable Repositories](https://www.baeldung.com/spring-data-composable-repositories)
- [Spring Data JPA Repository Populators](https://www.baeldung.com/spring-data-jpa-repository-populators)
- [Calling Stored Procedures from Spring Data JPA Repositories](https://www.baeldung.com/spring-data-jpa-stored-procedures)
+- [LIKE Queries in Spring JPA Repositories](https://www.baeldung.com/spring-jpa-like-queries)
+
- More articles: [[--> next]](../spring-data-jpa-repo-2)
### Eclipse Config
diff --git a/persistence-modules/spring-data-jpa-repo/pom.xml b/persistence-modules/spring-data-jpa-repo/pom.xml
index 1c58b5afa5..4ce19d83d0 100644
--- a/persistence-modules/spring-data-jpa-repo/pom.xml
+++ b/persistence-modules/spring-data-jpa-repo/pom.xml
@@ -42,6 +42,11 @@
org.springframework
spring-oxm
+
+ com.google.guava
+ guava
+ ${guava.version}
+
\ No newline at end of file
diff --git a/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/repository/Foo.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/repository/Foo.java
similarity index 87%
rename from persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/repository/Foo.java
rename to persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/repository/Foo.java
index 6833c4c556..27ebcf5875 100644
--- a/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/repository/Foo.java
+++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/repository/Foo.java
@@ -1,8 +1,13 @@
-package com.baeldung.spring.data.persistence.repository;
+package com.baeldung.repository;
-import javax.persistence.*;
import java.io.Serializable;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+
@Entity
public class Foo implements Serializable {
@Id
diff --git a/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/repository/FooService.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/repository/FooService.java
similarity index 83%
rename from persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/repository/FooService.java
rename to persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/repository/FooService.java
index cb09a92b82..98084240ac 100644
--- a/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/repository/FooService.java
+++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/repository/FooService.java
@@ -1,4 +1,4 @@
-package com.baeldung.spring.data.persistence.repository;
+package com.baeldung.repository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
diff --git a/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/repository/IFooDAO.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/repository/IFooDAO.java
similarity index 82%
rename from persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/repository/IFooDAO.java
rename to persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/repository/IFooDAO.java
index 20a81e7bfa..6ee74fe26c 100644
--- a/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/repository/IFooDAO.java
+++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/repository/IFooDAO.java
@@ -1,8 +1,9 @@
-package com.baeldung.spring.data.persistence.repository;
+package com.baeldung.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
+import org.springframework.stereotype.Repository;
public interface IFooDAO extends JpaRepository {
diff --git a/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/repository/IFooService.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/repository/IFooService.java
similarity index 50%
rename from persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/repository/IFooService.java
rename to persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/repository/IFooService.java
index 8ce6a2d1ae..6c4d36710c 100644
--- a/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/repository/IFooService.java
+++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/repository/IFooService.java
@@ -1,4 +1,4 @@
-package com.baeldung.spring.data.persistence.repository;
+package com.baeldung.repository;
public interface IFooService {
Foo create(Foo foo);
diff --git a/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/repository/PersistenceConfig.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/repository/PersistenceConfig.java
similarity index 93%
rename from persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/repository/PersistenceConfig.java
rename to persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/repository/PersistenceConfig.java
index f73ea94658..f3c9301bcf 100644
--- a/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/repository/PersistenceConfig.java
+++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/repository/PersistenceConfig.java
@@ -1,6 +1,9 @@
-package com.baeldung.spring.data.persistence.repository;
+package com.baeldung.repository;
+
+import java.util.Properties;
+
+import javax.sql.DataSource;
-import com.google.common.base.Preconditions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
@@ -16,15 +19,14 @@ import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
-import javax.sql.DataSource;
-import java.util.Properties;
+import com.google.common.base.Preconditions;
@Configuration
@PropertySource("classpath:persistence.properties")
-@ComponentScan("com.baeldung.spring.data.persistence.repository")
+@ComponentScan("com.baeldung.repository")
//@ImportResource("classpath*:*springDataConfig.xml")
@EnableTransactionManagement
-@EnableJpaRepositories(basePackages = "com.baeldung.spring.data.persistence.repository")
+@EnableJpaRepositories(basePackages = "com.baeldung.repository")
public class PersistenceConfig {
@Autowired
diff --git a/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/like/LikeApplication.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/spring/data/persistence/like/LikeApplication.java
similarity index 100%
rename from persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/like/LikeApplication.java
rename to persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/spring/data/persistence/like/LikeApplication.java
diff --git a/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/like/model/Movie.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/spring/data/persistence/like/model/Movie.java
similarity index 100%
rename from persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/like/model/Movie.java
rename to persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/spring/data/persistence/like/model/Movie.java
diff --git a/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/like/repository/MovieRepository.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/spring/data/persistence/like/repository/MovieRepository.java
similarity index 99%
rename from persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/like/repository/MovieRepository.java
rename to persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/spring/data/persistence/like/repository/MovieRepository.java
index 57befb5943..06e75222a3 100644
--- a/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/like/repository/MovieRepository.java
+++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/spring/data/persistence/like/repository/MovieRepository.java
@@ -1,11 +1,12 @@
package com.baeldung.spring.data.persistence.like.repository;
-import com.baeldung.spring.data.persistence.like.model.Movie;
+import java.util.List;
+
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
-import java.util.List;
+import com.baeldung.spring.data.persistence.like.model.Movie;
public interface MovieRepository extends CrudRepository {
diff --git a/persistence-modules/spring-data-jpa-repo/src/main/resources/persistence.properties b/persistence-modules/spring-data-jpa-repo/src/main/resources/persistence.properties
new file mode 100644
index 0000000000..05cb7a13b9
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-repo/src/main/resources/persistence.properties
@@ -0,0 +1,9 @@
+# jdbc.X
+jdbc.driverClassName=org.h2.Driver
+jdbc.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1
+jdbc.user=sa
+jdbc.pass=sa
+
+# hibernate.X
+hibernate.hbm2ddl.auto=create-drop
+hibernate.dialect=org.hibernate.dialect.H2Dialect
diff --git a/persistence-modules/spring-data-jpa-repo-2/src/main/resources/springDataConfig.xml b/persistence-modules/spring-data-jpa-repo/src/main/resources/springDataConfig.xml
similarity index 84%
rename from persistence-modules/spring-data-jpa-repo-2/src/main/resources/springDataConfig.xml
rename to persistence-modules/spring-data-jpa-repo/src/main/resources/springDataConfig.xml
index b2616d9eae..e581d514a4 100644
--- a/persistence-modules/spring-data-jpa-repo-2/src/main/resources/springDataConfig.xml
+++ b/persistence-modules/spring-data-jpa-repo/src/main/resources/springDataConfig.xml
@@ -7,5 +7,5 @@
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd"
>
-
+
\ No newline at end of file
diff --git a/persistence-modules/spring-data-jpa-repo-2/src/test/java/com/baeldung/spring/data/persistence/repository/FooServiceIntegrationTest.java b/persistence-modules/spring-data-jpa-repo/src/test/java/com/baeldung/repository/FooServiceIntegrationTest.java
similarity index 92%
rename from persistence-modules/spring-data-jpa-repo-2/src/test/java/com/baeldung/spring/data/persistence/repository/FooServiceIntegrationTest.java
rename to persistence-modules/spring-data-jpa-repo/src/test/java/com/baeldung/repository/FooServiceIntegrationTest.java
index 21990afb5e..9362b4c338 100644
--- a/persistence-modules/spring-data-jpa-repo-2/src/test/java/com/baeldung/spring/data/persistence/repository/FooServiceIntegrationTest.java
+++ b/persistence-modules/spring-data-jpa-repo/src/test/java/com/baeldung/repository/FooServiceIntegrationTest.java
@@ -1,4 +1,6 @@
-package com.baeldung.spring.data.persistence.repository;
+package com.baeldung.repository;
+
+import javax.sql.DataSource;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -7,8 +9,6 @@ import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
-import javax.sql.DataSource;
-
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = PersistenceConfig.class)
public class FooServiceIntegrationTest {
diff --git a/persistence-modules/spring-data-jpa-repo-2/src/test/java/com/baeldung/spring/data/persistence/like/MovieRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-repo/src/test/java/com/baeldung/spring/data/persistence/like/MovieRepositoryIntegrationTest.java
similarity index 99%
rename from persistence-modules/spring-data-jpa-repo-2/src/test/java/com/baeldung/spring/data/persistence/like/MovieRepositoryIntegrationTest.java
rename to persistence-modules/spring-data-jpa-repo/src/test/java/com/baeldung/spring/data/persistence/like/MovieRepositoryIntegrationTest.java
index 291926c127..dcb87a26a6 100644
--- a/persistence-modules/spring-data-jpa-repo-2/src/test/java/com/baeldung/spring/data/persistence/like/MovieRepositoryIntegrationTest.java
+++ b/persistence-modules/spring-data-jpa-repo/src/test/java/com/baeldung/spring/data/persistence/like/MovieRepositoryIntegrationTest.java
@@ -1,7 +1,12 @@
package com.baeldung.spring.data.persistence.like;
-import com.baeldung.spring.data.persistence.like.model.Movie;
-import com.baeldung.spring.data.persistence.like.repository.MovieRepository;
+import static org.junit.Assert.assertEquals;
+import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TEST_METHOD;
+
+import java.util.List;
+
+import javax.sql.DataSource;
+
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -9,11 +14,8 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.junit4.SpringRunner;
-import javax.sql.DataSource;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TEST_METHOD;
+import com.baeldung.spring.data.persistence.like.model.Movie;
+import com.baeldung.spring.data.persistence.like.repository.MovieRepository;
@RunWith(SpringRunner.class)
@Sql(scripts = { "/test-movie-data.sql" })
diff --git a/persistence-modules/spring-data-jpa-repo/src/test/resources/application-test.properties b/persistence-modules/spring-data-jpa-repo/src/test/resources/application-test.properties
index f9497c8f37..6f93e7d79d 100644
--- a/persistence-modules/spring-data-jpa-repo/src/test/resources/application-test.properties
+++ b/persistence-modules/spring-data-jpa-repo/src/test/resources/application-test.properties
@@ -1,2 +1,2 @@
-spring.jpa.hibernate.ddl-auto=update
-spring.datasource.url=jdbc:h2:mem:jpa3
\ No newline at end of file
+#spring.jpa.hibernate.ddl-auto=update
+#spring.datasource.url=jdbc:h2:mem:jpa3
\ No newline at end of file
diff --git a/persistence-modules/spring-data-jpa-repo/src/test/resources/test-movie-cleanup.sql b/persistence-modules/spring-data-jpa-repo/src/test/resources/test-movie-cleanup.sql
new file mode 100644
index 0000000000..e2e70a6a74
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-repo/src/test/resources/test-movie-cleanup.sql
@@ -0,0 +1 @@
+DELETE FROM movie;
\ No newline at end of file
diff --git a/persistence-modules/spring-data-jpa-repo/src/test/resources/test-movie-data.sql b/persistence-modules/spring-data-jpa-repo/src/test/resources/test-movie-data.sql
new file mode 100644
index 0000000000..3b706f14e3
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-repo/src/test/resources/test-movie-data.sql
@@ -0,0 +1,7 @@
+INSERT INTO movie(id,title,director,rating,duration) VALUES(1, 'Godzilla: King of the Monsters', ' Michael Dougherty', 'PG-13', 132);
+INSERT INTO movie(id,title,director,rating,duration) VALUES(2, 'Avengers: Endgame', 'Anthony Russo', 'PG-13', 181);
+INSERT INTO movie(id,title,director,rating,duration) VALUES(3, 'Captain Marvel', 'Anna Boden', 'PG-13', 123);
+INSERT INTO movie(id,title,director,rating,duration) VALUES(4, 'Dumbo', 'Tim Burton', 'PG', 112);
+INSERT INTO movie(id,title,director,rating,duration) VALUES(5, 'Booksmart', 'Olivia Wilde', 'R', 102);
+INSERT INTO movie(id,title,director,rating,duration) VALUES(6, 'Aladdin', 'Guy Ritchie', 'PG', 128);
+INSERT INTO movie(id,title,director,rating,duration) VALUES(7, 'The Sun Is Also a Star', 'Ry Russo-Young', 'PG-13', 100);
diff --git a/persistence-modules/spring-hibernate-5/pom.xml b/persistence-modules/spring-hibernate-5/pom.xml
index 32441473bb..3ad8f791df 100644
--- a/persistence-modules/spring-hibernate-5/pom.xml
+++ b/persistence-modules/spring-hibernate-5/pom.xml
@@ -131,7 +131,7 @@
1.10.6.RELEASE
4.2.1.RELEASE
- 5.2.10.Final
+ 5.6.15.Final
5.8.2.Final
8.2.0
9.0.0.M26
diff --git a/pom.xml b/pom.xml
index 7099dd8cbc..32b8e8c8c8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -701,7 +701,7 @@
apache-kafka
apache-libraries-2
apache-libraries
- apache-olingo
+ apache-olingo
apache-poi-2
apache-poi-3
apache-poi
@@ -710,7 +710,6 @@
apache-velocity
asciidoctor
asm
- atomikos
atomix
aws-modules
azure
@@ -727,7 +726,7 @@
dozer
drools
dubbo
-
+ feign
gcp-firebase
geotools
google-auto-project
@@ -889,7 +888,7 @@
spring-vault
spring-web-modules
spring-websockets
- static-analysis
+
tablesaw
tensorflow-java
testing-modules
@@ -946,7 +945,7 @@
apache-kafka
apache-libraries-2
apache-libraries
- apache-olingo
+ apache-olingo
apache-poi-2
apache-poi-3
apache-poi
@@ -955,7 +954,6 @@
apache-velocity
asciidoctor
asm
- atomikos
atomix
aws-modules
azure
@@ -972,7 +970,7 @@
dozer
drools
dubbo
-
+ feign
gcp-firebase
geotools
google-auto-project
@@ -1134,7 +1132,7 @@
spring-vault
spring-web-modules
spring-websockets
- static-analysis
+
tablesaw
tensorflow-java
testing-modules
diff --git a/quarkus-modules/quarkus-extension/quarkus-liquibase/runtime/pom.xml b/quarkus-modules/quarkus-extension/quarkus-liquibase/runtime/pom.xml
index 95916932a1..f1fe9eec5c 100644
--- a/quarkus-modules/quarkus-extension/quarkus-liquibase/runtime/pom.xml
+++ b/quarkus-modules/quarkus-extension/quarkus-liquibase/runtime/pom.xml
@@ -66,8 +66,7 @@
- 3.8.1
- 3.8.1
+ 4.25.0
\ No newline at end of file
diff --git a/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/config/WebSecurityConfig.java b/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/config/WebSecurityConfig.java
index 687a827448..e453f33d5e 100644
--- a/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/config/WebSecurityConfig.java
+++ b/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/config/WebSecurityConfig.java
@@ -4,9 +4,11 @@ import io.jsonwebtoken.JwtException;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.jjwtfun.service.SecretService;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.csrf.CsrfFilter;
import org.springframework.security.web.csrf.CsrfToken;
import org.springframework.security.web.csrf.CsrfTokenRepository;
@@ -21,19 +23,19 @@ import java.io.IOException;
import java.util.Arrays;
@Configuration
-public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
+public class WebSecurityConfig {
@Autowired
- CsrfTokenRepository jwtCsrfTokenRepository;
+ private CsrfTokenRepository jwtCsrfTokenRepository;
@Autowired
- SecretService secretService;
+ private SecretService secretService;
// ordered so we can use binary search below
- private String[] ignoreCsrfAntMatchers = { "/dynamic-builder-compress", "/dynamic-builder-general", "/dynamic-builder-specific", "/set-secrets" };
+ private final String[] ignoreCsrfAntMatchers = { "/dynamic-builder-compress", "/dynamic-builder-general", "/dynamic-builder-specific", "/set-secrets" };
- @Override
- protected void configure(HttpSecurity http) throws Exception {
+ @Bean
+ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.addFilterAfter(new JwtCsrfValidatorFilter(), CsrfFilter.class)
.csrf()
.csrfTokenRepository(jwtCsrfTokenRepository)
@@ -42,6 +44,8 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
.authorizeRequests()
.antMatchers("/**")
.permitAll();
+
+ return http.build();
}
private class JwtCsrfValidatorFilter extends OncePerRequestFilter {
diff --git a/spring-5-webflux-2/pom.xml b/spring-5-webflux-2/pom.xml
index 34cbda6c18..efb99e06d5 100644
--- a/spring-5-webflux-2/pom.xml
+++ b/spring-5-webflux-2/pom.xml
@@ -86,6 +86,7 @@
com.squareup.okhttp3
mockwebserver
+ 4.12.0
diff --git a/spring-5-webflux/pom.xml b/spring-5-webflux/pom.xml
index 69de83c227..fe6dbe5292 100644
--- a/spring-5-webflux/pom.xml
+++ b/spring-5-webflux/pom.xml
@@ -74,6 +74,7 @@
com.squareup.okhttp3
mockwebserver
+ 4.12.0
diff --git a/spring-boot-modules/spring-boot-groovy/pom.xml b/spring-boot-modules/spring-boot-groovy/pom.xml
index 151160bde5..677e07db2d 100644
--- a/spring-boot-modules/spring-boot-groovy/pom.xml
+++ b/spring-boot-modules/spring-boot-groovy/pom.xml
@@ -1,7 +1,7 @@
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
com.baeldung.app
spring-boot-groovy
@@ -10,9 +10,10 @@
Spring Boot Todo Application with Groovy
- com.baeldung.spring-boot-modules
- spring-boot-modules
- 1.0.0-SNAPSHOT
+ com.baeldung
+ parent-boot-3
+ 0.0.1-SNAPSHOT
+ ../../parent-boot-3
@@ -25,7 +26,7 @@
spring-boot-starter-web
- org.codehaus.groovy
+ org.apache.groovy
groovy
${groovy.version}
@@ -39,6 +40,11 @@
h2
runtime
+
+ io.rest-assured
+ rest-assured
+ test
+
@@ -71,8 +77,8 @@
com.baeldung.springwithgroovy.SpringBootGroovyApplication
- 3.0.13
- 1.9.0
+ 4.0.11
+ 3.0.2
\ No newline at end of file
diff --git a/spring-boot-modules/spring-boot-groovy/src/main/groovy/com/baeldung/springwithgroovy/entity/Todo.groovy b/spring-boot-modules/spring-boot-groovy/src/main/groovy/com/baeldung/springwithgroovy/entity/Todo.groovy
index 000d981701..31274e1f07 100644
--- a/spring-boot-modules/spring-boot-groovy/src/main/groovy/com/baeldung/springwithgroovy/entity/Todo.groovy
+++ b/spring-boot-modules/spring-boot-groovy/src/main/groovy/com/baeldung/springwithgroovy/entity/Todo.groovy
@@ -1,11 +1,11 @@
package com.baeldung.springwithgroovy.entity
-import javax.persistence.Column
-import javax.persistence.Entity
-import javax.persistence.GeneratedValue
-import javax.persistence.GenerationType
-import javax.persistence.Id
-import javax.persistence.Table
+import jakarta.persistence.Column
+import jakarta.persistence.Entity
+import jakarta.persistence.GeneratedValue
+import jakarta.persistence.GenerationType
+import jakarta.persistence.Id
+import jakarta.persistence.Table
@Entity
@Table(name = 'todo')
diff --git a/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/caffeine/SecurityConfiguration.java b/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/caffeine/SecurityConfiguration.java
index 7f3ad7988f..e63726c926 100644
--- a/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/caffeine/SecurityConfiguration.java
+++ b/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/caffeine/SecurityConfiguration.java
@@ -1,9 +1,10 @@
package com.baeldung.caffeine;
+import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
-import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+import org.springframework.security.web.SecurityFilterChain;
/**
* Because the POM imports Spring Security, we need a simple security
@@ -11,14 +12,14 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur
*/
@Configuration
@EnableWebSecurity
-public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
+public class SecurityConfiguration {
- @Override
- protected void configure(HttpSecurity http) throws Exception {
+ @Bean
+ public SecurityFilterChain securityFilter(HttpSecurity http) throws Exception {
http.csrf().disable();
- http.authorizeRequests()
+ return http.authorizeRequests()
.antMatchers("/**")
- .permitAll();
+ .permitAll().and().build();
}
}
diff --git a/spring-boot-modules/spring-boot-mvc-5/pom.xml b/spring-boot-modules/spring-boot-mvc-5/pom.xml
index a516cab049..10a58a6a59 100644
--- a/spring-boot-modules/spring-boot-mvc-5/pom.xml
+++ b/spring-boot-modules/spring-boot-mvc-5/pom.xml
@@ -49,6 +49,10 @@
commons-configuration
${commons-configuration.version}
+
+ org.springframework.boot
+ spring-boot-starter-aop
+
@@ -61,6 +65,14 @@
JAR
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ 9
+ 9
+
+
diff --git a/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/ModifyRequestApp.java b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/ModifyRequestApp.java
new file mode 100644
index 0000000000..7dd937d5b8
--- /dev/null
+++ b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/ModifyRequestApp.java
@@ -0,0 +1,11 @@
+package com.baeldung.modifyrequest;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication(scanBasePackages = "com.baeldung.modifyrequest")
+public class ModifyRequestApp {
+ public static void main(String[] args) {
+ SpringApplication.run(ModifyRequestApp.class, args);
+ }
+}
diff --git a/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/aop/EscapeHtmlAspect.java b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/aop/EscapeHtmlAspect.java
new file mode 100644
index 0000000000..d4533dcf0b
--- /dev/null
+++ b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/aop/EscapeHtmlAspect.java
@@ -0,0 +1,78 @@
+package com.baeldung.modifyrequest.aop;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.annotation.Profile;
+import org.springframework.core.MethodParameter;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpInputMessage;
+import org.springframework.http.converter.HttpMessageConverter;
+import org.springframework.web.bind.annotation.RestControllerAdvice;
+import org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice;
+
+import java.io.*;
+import java.lang.reflect.Type;
+import java.nio.charset.StandardCharsets;
+
+@RestControllerAdvice
+@Profile("aspectExample")
+public class EscapeHtmlAspect implements RequestBodyAdvice {
+
+ private static final Logger logger = LoggerFactory.getLogger(EscapeHtmlAspect.class);
+
+ @Override
+ public boolean supports(MethodParameter methodParameter, Type targetType, Class extends HttpMessageConverter>> converterType) {
+ //Apply this to all Controllers
+ return true;
+ }
+
+ @Override
+ public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter, Type targetType,
+ Class extends HttpMessageConverter>> converterType) throws IOException {
+ logger.info("beforeBodyRead called");
+ InputStream inputStream = inputMessage.getBody();
+ return new HttpInputMessage() {
+ @Override
+ public InputStream getBody() throws IOException {
+ return new ByteArrayInputStream(escapeHtml(inputStream).getBytes(StandardCharsets.UTF_8));
+ }
+
+ @Override
+ public HttpHeaders getHeaders() {
+ return inputMessage.getHeaders();
+ }
+ };
+ }
+
+ @Override
+ public Object afterBodyRead(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType,
+ Class extends HttpMessageConverter>> converterType) {
+ // Return the modified object after reading the body
+ return body;
+ }
+
+ @Override
+ public Object handleEmptyBody(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType,
+ Class extends HttpMessageConverter>> converterType) {
+ //return the original body
+ return body;
+ }
+
+ private String escapeHtml(InputStream inputStream) throws IOException {
+ StringBuilder stringBuilder = new StringBuilder();
+ BufferedReader bufferedReader = null;
+ try (inputStream) {
+ bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
+ char[] charBuffer = new char[128];
+ int bytesRead = -1;
+ while ((bytesRead = bufferedReader.read(charBuffer)) > 0) {
+ stringBuilder.append(charBuffer, 0, bytesRead);
+ }
+ }
+ String input = stringBuilder.toString();
+ // Escape HTML characters
+ return input.replaceAll("&", "&")
+ .replaceAll("<", "<")
+ .replaceAll(">", ">");
+ }
+}
diff --git a/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/config/WebMvcConfiguration.java b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/config/WebMvcConfiguration.java
new file mode 100644
index 0000000000..2fc1fbc310
--- /dev/null
+++ b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/config/WebMvcConfiguration.java
@@ -0,0 +1,26 @@
+package com.baeldung.modifyrequest.config;
+
+import com.baeldung.modifyrequest.interceptor.EscapeHtmlRequestInterceptor;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Profile;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+@Configuration
+@Profile("interceptorExample")
+public class WebMvcConfiguration implements WebMvcConfigurer {
+ private static final Logger logger = LoggerFactory.getLogger(WebMvcConfiguration.class);
+
+ @Override
+ public void addInterceptors(InterceptorRegistry registry) {
+ logger.info("addInterceptors() called");
+ registry.addInterceptor(new EscapeHtmlRequestInterceptor())
+ .addPathPatterns("/save");
+
+ WebMvcConfigurer.super.addInterceptors(registry);
+ }
+}
+
diff --git a/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/controller/UserController.java b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/controller/UserController.java
new file mode 100644
index 0000000000..26450dd70d
--- /dev/null
+++ b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/controller/UserController.java
@@ -0,0 +1,23 @@
+package com.baeldung.modifyrequest.controller;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("/")
+public class UserController {
+ Logger logger = LoggerFactory.getLogger(UserController.class);
+
+ @PostMapping(value = "save")
+ public ResponseEntity saveUser(@RequestBody String user) {
+ logger.info("save user info into database");
+ ResponseEntity responseEntity = new ResponseEntity<>(user, HttpStatus.CREATED);
+ return responseEntity;
+ }
+}
diff --git a/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/filter/EscapeHtmlFilter.java b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/filter/EscapeHtmlFilter.java
new file mode 100644
index 0000000000..45cad3be1c
--- /dev/null
+++ b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/filter/EscapeHtmlFilter.java
@@ -0,0 +1,27 @@
+package com.baeldung.modifyrequest.filter;
+
+import com.baeldung.modifyrequest.requestwrapper.EscapeHtmlRequestWrapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.annotation.Profile;
+import org.springframework.core.annotation.Order;
+import org.springframework.stereotype.Component;
+
+import javax.servlet.*;
+import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
+
+@Component
+@Order(1)
+@Profile("filterExample")
+public class EscapeHtmlFilter implements Filter {
+ Logger logger = LoggerFactory.getLogger(EscapeHtmlFilter.class);
+
+ @Override
+ public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
+ throws IOException, ServletException {
+ logger.info("Modify the request");
+
+ filterChain.doFilter(new EscapeHtmlRequestWrapper((HttpServletRequest) servletRequest), servletResponse);
+ }
+}
diff --git a/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/interceptor/EscapeHtmlRequestInterceptor.java b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/interceptor/EscapeHtmlRequestInterceptor.java
new file mode 100644
index 0000000000..1ad39605e5
--- /dev/null
+++ b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/interceptor/EscapeHtmlRequestInterceptor.java
@@ -0,0 +1,19 @@
+package com.baeldung.modifyrequest.interceptor;
+
+import com.baeldung.modifyrequest.requestwrapper.EscapeHtmlRequestWrapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.servlet.HandlerInterceptor;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+public class EscapeHtmlRequestInterceptor implements HandlerInterceptor {
+ private static final Logger logger = LoggerFactory.getLogger(EscapeHtmlRequestInterceptor.class);
+
+ @Override
+ public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
+ EscapeHtmlRequestWrapper escapeHtmlRequestWrapper = new EscapeHtmlRequestWrapper(request);
+ return true;
+ }
+}
diff --git a/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/requestwrapper/EscapeHtmlRequestWrapper.java b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/requestwrapper/EscapeHtmlRequestWrapper.java
new file mode 100644
index 0000000000..e7b3abbc1f
--- /dev/null
+++ b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/modifyrequest/requestwrapper/EscapeHtmlRequestWrapper.java
@@ -0,0 +1,67 @@
+package com.baeldung.modifyrequest.requestwrapper;
+
+import javax.servlet.ReadListener;
+import javax.servlet.ServletInputStream;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+import java.io.*;
+
+public class EscapeHtmlRequestWrapper extends HttpServletRequestWrapper {
+ private String body = null;
+ public EscapeHtmlRequestWrapper(HttpServletRequest request) throws IOException {
+ super(request);
+ this.body = this.escapeHtml(request);
+ }
+
+ private String escapeHtml(HttpServletRequest request) throws IOException {
+ StringBuilder stringBuilder = new StringBuilder();
+ BufferedReader bufferedReader = null;
+ try (InputStream inputStream = request.getInputStream()) {
+ bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
+ char[] charBuffer = new char[128];
+ int bytesRead = -1;
+ while ((bytesRead = bufferedReader.read(charBuffer)) > 0) {
+ stringBuilder.append(charBuffer, 0, bytesRead);
+ }
+ }
+ String input = stringBuilder.toString();
+ // Escape HTML characters
+ return input.replaceAll("&", "&")
+ .replaceAll("<", "<")
+ .replaceAll(">", ">")
+ .replaceAll("'", "'");
+ }
+
+ @Override
+ public ServletInputStream getInputStream() {
+ final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(body.getBytes());
+ ServletInputStream servletInputStream = new ServletInputStream() {
+
+ @Override
+ public int read() {
+ return byteArrayInputStream.read();
+ }
+
+ @Override
+ public boolean isFinished() {
+ return false;
+ }
+
+ @Override
+ public boolean isReady() {
+ return false;
+ }
+
+ @Override
+ public void setReadListener(ReadListener listener) {
+
+ }
+ };
+ return servletInputStream;
+ }
+
+ @Override
+ public BufferedReader getReader() throws IOException {
+ return new BufferedReader(new InputStreamReader(this.getInputStream()));
+ }
+}
diff --git a/spring-boot-modules/spring-boot-mvc-5/src/main/resources/modifyrequest/filter-sequence-design.puml b/spring-boot-modules/spring-boot-mvc-5/src/main/resources/modifyrequest/filter-sequence-design.puml
new file mode 100644
index 0000000000..41689ac723
--- /dev/null
+++ b/spring-boot-modules/spring-boot-mvc-5/src/main/resources/modifyrequest/filter-sequence-design.puml
@@ -0,0 +1,31 @@
+@startuml
+'https://plantuml.com/sequence-diagram
+skinparam sequenceMessageAlign direction
+skinparam handwritten true
+skinparam sequence {
+ParticipantBackgroundColor beige
+ParticipantPadding 50
+}
+
+autonumber
+
+Browser -[#63b175]> Filter: HTTP Request
+activate Browser
+activate Filter
+Filter -[#63b175]> Filter: doFilter()
+Filter -[#63b175]> DispatcherServlet: HTTP Request
+activate DispatcherServlet
+
+
+DispatcherServlet -[#63b175]> Controller: HTTP Request
+activate Controller
+Controller --[#63b175]> DispatcherServlet: HTTP Response
+deactivate Controller
+
+DispatcherServlet --[#63b175]> Filter: HTTP Response
+deactivate DispatcherServlet
+
+Filter --[#63b175]> Browser: HTTP Response
+deactivate Filter
+deactivate Browser
+@enduml
\ No newline at end of file
diff --git a/spring-boot-modules/spring-boot-mvc-5/src/main/resources/modifyrequest/interceptor-sequence-design.puml b/spring-boot-modules/spring-boot-mvc-5/src/main/resources/modifyrequest/interceptor-sequence-design.puml
new file mode 100644
index 0000000000..429b8182ca
--- /dev/null
+++ b/spring-boot-modules/spring-boot-mvc-5/src/main/resources/modifyrequest/interceptor-sequence-design.puml
@@ -0,0 +1,33 @@
+@startuml
+'https://plantuml.com/sequence-diagram
+skinparam sequenceMessageAlign direction
+skinparam handwritten true
+skinparam sequence {
+ParticipantBackgroundColor beige
+ParticipantPadding 50
+}
+
+autonumber
+
+Browser -[#63b175]> Filter: Http Request
+activate Browser
+activate Filter
+Filter -[#63b175]> DispatcherServlet: Http Request
+activate DispatcherServlet
+
+DispatcherServlet -[#63b175]> Interceptor: Http Request
+activate Interceptor
+Interceptor -[#63b175]> Interceptor: preHandle()
+Interceptor -[#63b175]> Controller: Http Request
+activate Controller
+Controller --[#63b175]> Interceptor: Http Response
+deactivate Controller
+Interceptor --[#63b175]> DispatcherServlet: Http Response
+deactivate Interceptor
+DispatcherServlet --[#63b175]> Filter: Http Response
+deactivate DispatcherServlet
+
+Filter --[#63b175]> Browser: Http Response
+deactivate Filter
+deactivate Browser
+@enduml
\ No newline at end of file
diff --git a/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlAspectIntegrationTest.java b/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlAspectIntegrationTest.java
new file mode 100644
index 0000000000..ef18591ccb
--- /dev/null
+++ b/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlAspectIntegrationTest.java
@@ -0,0 +1,54 @@
+package com.baeldung.modifyrequest;
+
+import com.baeldung.modifyrequest.controller.UserController;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
+import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
+import org.springframework.http.MediaType;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
+import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
+
+import java.net.URI;
+import java.util.Map;
+
+@ExtendWith(SpringExtension.class)
+@AutoConfigureMockMvc
+@WebMvcTest(UserController.class)
+@ActiveProfiles("aspectExample")
+public class EscapeHtmlAspectIntegrationTest {
+ Logger logger = LoggerFactory.getLogger(EscapeHtmlAspectIntegrationTest.class);
+
+ @Autowired
+ private MockMvc mockMvc;
+ @Test
+ void givenAspect_whenEscapeHtmlAspect_thenEscapeHtml() throws Exception {
+
+ Map requestBody = Map.of(
+ "name", "James Cameron",
+ "email", "james@gmail.com"
+ );
+
+ Map expectedResponseBody = Map.of(
+ "name", "James Cameron",
+ "email", "<script>alert()</script>james@gmail.com"
+ );
+
+ ObjectMapper objectMapper = new ObjectMapper();
+
+ mockMvc.perform(MockMvcRequestBuilders.post(URI.create("/save"))
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(objectMapper.writeValueAsString(requestBody)))
+ .andExpect(MockMvcResultMatchers.status()
+ .isCreated())
+ .andExpect(MockMvcResultMatchers.content()
+ .json(objectMapper.writeValueAsString(expectedResponseBody)));
+ }
+}
diff --git a/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlFilterIntegrationTest.java b/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlFilterIntegrationTest.java
new file mode 100644
index 0000000000..c813827422
--- /dev/null
+++ b/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlFilterIntegrationTest.java
@@ -0,0 +1,51 @@
+package com.baeldung.modifyrequest;
+
+import com.baeldung.modifyrequest.controller.UserController;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
+import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
+import org.springframework.http.MediaType;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
+import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
+
+import java.net.URI;
+import java.util.Map;
+
+@ExtendWith(SpringExtension.class)
+@AutoConfigureMockMvc
+@WebMvcTest(UserController.class)
+@ActiveProfiles("filterExample")
+public class EscapeHtmlFilterIntegrationTest {
+ Logger logger = LoggerFactory.getLogger(EscapeHtmlFilterIntegrationTest.class);
+
+ @Autowired
+ private MockMvc mockMvc;
+ @Test
+ void givenFilter_whenEscapeHtmlFilter_thenEscapeHtml() throws Exception {
+ Map requestBody = Map.of(
+ "name", "James Cameron",
+ "email", "james@gmail.com"
+ );
+
+ Map expectedResponseBody = Map.of(
+ "name", "James Cameron",
+ "email", "<script>alert()</script>james@gmail.com"
+ );
+
+ ObjectMapper objectMapper = new ObjectMapper();
+
+ mockMvc.perform(MockMvcRequestBuilders.post(URI.create("/save"))
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(objectMapper.writeValueAsString(requestBody))).andExpect(MockMvcResultMatchers.status()
+ .isCreated()).andExpect(MockMvcResultMatchers.content()
+ .json(objectMapper.writeValueAsString(expectedResponseBody)));
+ }
+}
diff --git a/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlInterceptorIntegrationTest.java b/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlInterceptorIntegrationTest.java
new file mode 100644
index 0000000000..9afc7f7e5a
--- /dev/null
+++ b/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/modifyrequest/EscapeHtmlInterceptorIntegrationTest.java
@@ -0,0 +1,46 @@
+package com.baeldung.modifyrequest;
+
+import com.baeldung.modifyrequest.controller.UserController;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
+import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
+import org.springframework.http.MediaType;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
+import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
+
+import java.net.URI;
+import java.util.Map;
+
+
+@ExtendWith(SpringExtension.class)
+@AutoConfigureMockMvc
+@WebMvcTest(UserController.class)
+@ActiveProfiles("interceptorExample")
+public class EscapeHtmlInterceptorIntegrationTest {
+ Logger logger = LoggerFactory.getLogger(EscapeHtmlInterceptorIntegrationTest.class);
+
+ @Autowired
+ private MockMvc mockMvc;
+
+ @Test
+ void givenInterceptor_whenEscapeHtmlInterceptor_thenEscapeHtml() throws Exception {
+ Map requestBody = Map.of(
+ "name", "James Cameron",
+ "email", "james@gmail.com"
+ );
+
+ ObjectMapper objectMapper = new ObjectMapper();
+ mockMvc.perform(MockMvcRequestBuilders.post(URI.create("/save"))
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(objectMapper.writeValueAsString(requestBody))).andExpect(MockMvcResultMatchers.status()
+ .is4xxClientError());
+ }
+}
diff --git a/spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/spring/boot/management/logging/SecurityConfig.java b/spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/spring/boot/management/logging/SecurityConfig.java
index 45cc1ebb33..6870f4e6bb 100644
--- a/spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/spring/boot/management/logging/SecurityConfig.java
+++ b/spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/spring/boot/management/logging/SecurityConfig.java
@@ -1,14 +1,16 @@
package com.baeldung.spring.boot.management.logging;
+import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
-import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+import org.springframework.security.web.SecurityFilterChain;
@Configuration
-public class SecurityConfig extends WebSecurityConfigurerAdapter {
- @Override
- protected void configure(HttpSecurity http) throws Exception {
- http.csrf()
- .ignoringAntMatchers("/actuator/**");
+public class SecurityConfig {
+ @Bean
+ public SecurityFilterChain securityFilter(HttpSecurity http) throws Exception {
+ return http.csrf()
+ .ignoringAntMatchers("/actuator/**").and()
+ .build();
}
}
diff --git a/spring-cloud-modules/spring-cloud-openfeign/src/main/java/com/baeldung/cloud/openfeign/oauthfeign/OAuth2WebSecurityConfigurerAdapter.java b/spring-cloud-modules/spring-cloud-openfeign/src/main/java/com/baeldung/cloud/openfeign/oauthfeign/OAuth2WebSecurityConfigurerAdapter.java
index af60c3849b..6efacc03b1 100644
--- a/spring-cloud-modules/spring-cloud-openfeign/src/main/java/com/baeldung/cloud/openfeign/oauthfeign/OAuth2WebSecurityConfigurerAdapter.java
+++ b/spring-cloud-modules/spring-cloud-openfeign/src/main/java/com/baeldung/cloud/openfeign/oauthfeign/OAuth2WebSecurityConfigurerAdapter.java
@@ -1,19 +1,23 @@
package com.baeldung.cloud.openfeign.oauthfeign;
+import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
-import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+import org.springframework.security.web.SecurityFilterChain;
@Configuration
-public class OAuth2WebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
+public class OAuth2WebSecurityConfigurerAdapter {
- @Override
- protected void configure(HttpSecurity http) throws Exception {
+ @Bean
+ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.csrf()
.disable()
.oauth2Client();
+
http
.authorizeRequests().anyRequest().permitAll();
+
+ return http.build();
}
}
diff --git a/spring-cucumber/pom.xml b/spring-cucumber/pom.xml
index 042e81971f..0b0e38a2be 100644
--- a/spring-cucumber/pom.xml
+++ b/spring-cucumber/pom.xml
@@ -11,9 +11,9 @@
com.baeldung
- parent-boot-2
+ parent-boot-3
0.0.1-SNAPSHOT
- ../parent-boot-2
+ ../parent-boot-3
@@ -53,16 +53,17 @@
- org.apache.commons
+ commons-io
commons-io
${commons-io.version}
+
+ com.baeldung.SpringDemoApplication
7.14.0
- 1.3.2
- 5.10.0
+ 5.10.1
\ No newline at end of file
diff --git a/spring-cucumber/src/main/java/com/baeldung/cucumberoptions/HealthCheckController.java b/spring-cucumber/src/main/java/com/baeldung/cucumberoptions/HealthCheckController.java
index 637dbdb540..70a917d999 100644
--- a/spring-cucumber/src/main/java/com/baeldung/cucumberoptions/HealthCheckController.java
+++ b/spring-cucumber/src/main/java/com/baeldung/cucumberoptions/HealthCheckController.java
@@ -3,6 +3,7 @@ package com.baeldung.cucumberoptions;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
import org.springframework.http.HttpStatus;
+import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -11,12 +12,12 @@ import org.springframework.web.bind.annotation.RestController;
public class HealthCheckController {
@GetMapping(path = "/v1/status", produces = APPLICATION_JSON_VALUE)
- public HttpStatus getV1Status() {
+ public HttpStatusCode getV1Status() {
return ResponseEntity.ok().build().getStatusCode();
}
@GetMapping(path = "/v2/status", produces = APPLICATION_JSON_VALUE)
- public HttpStatus getV2Status() {
+ public HttpStatusCode getV2Status() {
return ResponseEntity.ok().build().getStatusCode();
}
}
\ No newline at end of file
diff --git a/spring-cucumber/src/test/java/com/baeldung/SpringIntegrationTest.java b/spring-cucumber/src/test/java/com/baeldung/SpringIntegrationTest.java
index 7b5c4e21ff..f243c68237 100644
--- a/spring-cucumber/src/test/java/com/baeldung/SpringIntegrationTest.java
+++ b/spring-cucumber/src/test/java/com/baeldung/SpringIntegrationTest.java
@@ -9,6 +9,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.http.HttpMethod;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.HttpStatusCode;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.web.client.ResponseErrorHandler;
@@ -69,7 +71,7 @@ public class SpringIntegrationTest {
@Override
public boolean hasError(ClientHttpResponse response) throws IOException {
- hadError = response.getRawStatusCode() >= 400;
+ hadError = response.getStatusCode().value() >= 400;
return hadError;
}
diff --git a/spring-cucumber/src/test/java/com/baeldung/StepDefsIntegrationTest.java b/spring-cucumber/src/test/java/com/baeldung/StepDefsIntegrationTest.java
index 9611e95dcf..e4e0b2a883 100644
--- a/spring-cucumber/src/test/java/com/baeldung/StepDefsIntegrationTest.java
+++ b/spring-cucumber/src/test/java/com/baeldung/StepDefsIntegrationTest.java
@@ -5,6 +5,7 @@ import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import org.springframework.http.HttpStatus;
+import org.springframework.http.HttpStatusCode;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
@@ -29,7 +30,7 @@ public class StepDefsIntegrationTest extends SpringIntegrationTest {
@Then("^the client receives status code of (\\d+)$")
public void the_client_receives_status_code_of(int statusCode) throws Throwable {
- final HttpStatus currentStatusCode = latestResponse.getTheResponse().getStatusCode();
+ final HttpStatusCode currentStatusCode = latestResponse.getTheResponse().getStatusCode();
assertThat("status code is incorrect : " + latestResponse.getBody(), currentStatusCode.value(), is(statusCode));
}
diff --git a/spring-cucumber/src/test/java/com/baeldung/cucumberoptions/HealthCheckStepDefsIntegrationTest.java b/spring-cucumber/src/test/java/com/baeldung/cucumberoptions/HealthCheckStepDefsIntegrationTest.java
index 999adadbef..7304f269e7 100644
--- a/spring-cucumber/src/test/java/com/baeldung/cucumberoptions/HealthCheckStepDefsIntegrationTest.java
+++ b/spring-cucumber/src/test/java/com/baeldung/cucumberoptions/HealthCheckStepDefsIntegrationTest.java
@@ -3,7 +3,8 @@ package com.baeldung.cucumberoptions;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
-import org.springframework.http.HttpStatus;
+
+import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
@@ -32,7 +33,7 @@ public class HealthCheckStepDefsIntegrationTest extends SpringIntegrationTest {
@Then("^the client receives (\\d+) status code$")
public void verifyStatusCode(int statusCode) throws Throwable {
- final HttpStatus currentStatusCode = statusResponse.getStatusCode();
+ final HttpStatusCode currentStatusCode = statusResponse.getStatusCode();
assertThat(currentStatusCode.value(), is(statusCode));
}
}
\ No newline at end of file
diff --git a/spring-di-4/README.md b/spring-di-4/README.md
index 8e73aff437..bed8b5a78d 100644
--- a/spring-di-4/README.md
+++ b/spring-di-4/README.md
@@ -7,4 +7,5 @@ This module contains articles about dependency injection with Spring
- [Using @Autowired in Abstract Classes](https://www.baeldung.com/spring-autowired-abstract-class)
- [Spring @Component Annotation](https://www.baeldung.com/spring-component-annotation)
- [Why Is Field Injection Not Recommended?](https://www.baeldung.com/java-spring-field-injection-cons)
+- [Setting a Spring Bean to Null](https://www.baeldung.com/spring-setting-bean-null)
- More articles: [[<-- prev]](../spring-di-3)
diff --git a/spring-jinq/pom.xml b/spring-jinq/pom.xml
index 14ac366e74..c1dee7fa9f 100644
--- a/spring-jinq/pom.xml
+++ b/spring-jinq/pom.xml
@@ -10,9 +10,9 @@
com.baeldung
- parent-boot-2
+ parent-boot-3
0.0.1-SNAPSHOT
- ../parent-boot-2
+ ../parent-boot-3
@@ -35,6 +35,11 @@
org.springframework
spring-orm
+
+ org.hibernate.orm
+ hibernate-core
+ ${hibernate-core.version}
+
org.springframework.boot
@@ -58,7 +63,8 @@
- 1.8.29
+ 2.0.1
+ 6.4.0.Final
\ No newline at end of file
diff --git a/spring-jinq/src/main/java/com/baeldung/spring/jinq/config/JinqProviderConfiguration.java b/spring-jinq/src/main/java/com/baeldung/spring/jinq/config/JinqProviderConfiguration.java
index 6d921045b7..01e16cf0f7 100644
--- a/spring-jinq/src/main/java/com/baeldung/spring/jinq/config/JinqProviderConfiguration.java
+++ b/spring-jinq/src/main/java/com/baeldung/spring/jinq/config/JinqProviderConfiguration.java
@@ -1,6 +1,6 @@
package com.baeldung.spring.jinq.config;
-import javax.persistence.EntityManagerFactory;
+import jakarta.persistence.EntityManagerFactory;
import org.jinq.jpa.JinqJPAStreamProvider;
import org.springframework.beans.factory.annotation.Autowired;
diff --git a/spring-jinq/src/main/java/com/baeldung/spring/jinq/entities/Car.java b/spring-jinq/src/main/java/com/baeldung/spring/jinq/entities/Car.java
index 263e6c7622..a0b9620629 100644
--- a/spring-jinq/src/main/java/com/baeldung/spring/jinq/entities/Car.java
+++ b/spring-jinq/src/main/java/com/baeldung/spring/jinq/entities/Car.java
@@ -1,19 +1,23 @@
package com.baeldung.spring.jinq.entities;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.OneToOne;
+import jakarta.persistence.Entity;
+import jakarta.persistence.Id;
+import jakarta.persistence.JoinColumn;
+import jakarta.persistence.ManyToOne;
+
+
@Entity(name = "CAR")
public class Car {
+ @Id
private String model;
private String description;
private int year;
private String engine;
+ @ManyToOne
+ @JoinColumn(name = "name")
private Manufacturer manufacturer;
- @Id
public String getModel() {
return model;
}
@@ -46,8 +50,6 @@ public class Car {
this.engine = engine;
}
- @OneToOne
- @JoinColumn(name = "name")
public Manufacturer getManufacturer() {
return manufacturer;
}
diff --git a/spring-jinq/src/main/java/com/baeldung/spring/jinq/entities/Manufacturer.java b/spring-jinq/src/main/java/com/baeldung/spring/jinq/entities/Manufacturer.java
index f6e5fd23de..0021e45658 100644
--- a/spring-jinq/src/main/java/com/baeldung/spring/jinq/entities/Manufacturer.java
+++ b/spring-jinq/src/main/java/com/baeldung/spring/jinq/entities/Manufacturer.java
@@ -2,18 +2,19 @@ package com.baeldung.spring.jinq.entities;
import java.util.List;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.OneToMany;
+import jakarta.persistence.Entity;
+import jakarta.persistence.Id;
+import jakarta.persistence.OneToMany;
@Entity(name = "MANUFACTURER")
public class Manufacturer {
+ @Id
private String name;
private String city;
+ @OneToMany(mappedBy = "model")
private List cars;
- @Id
public String getName() {
return name;
}
@@ -30,7 +31,6 @@ public class Manufacturer {
this.city = city;
}
- @OneToMany(mappedBy = "model")
public List getCars() {
return cars;
}
@@ -38,5 +38,4 @@ public class Manufacturer {
public void setCars(List cars) {
this.cars = cars;
}
-
}
diff --git a/spring-jinq/src/main/java/com/baeldung/spring/jinq/repositories/BaseJinqRepositoryImpl.java b/spring-jinq/src/main/java/com/baeldung/spring/jinq/repositories/BaseJinqRepositoryImpl.java
index 42b81ecc59..e85231f537 100644
--- a/spring-jinq/src/main/java/com/baeldung/spring/jinq/repositories/BaseJinqRepositoryImpl.java
+++ b/spring-jinq/src/main/java/com/baeldung/spring/jinq/repositories/BaseJinqRepositoryImpl.java
@@ -1,7 +1,7 @@
package com.baeldung.spring.jinq.repositories;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
+import jakarta.persistence.EntityManager;
+import jakarta.persistence.PersistenceContext;
import org.jinq.jpa.JPAJinqStream;
import org.jinq.jpa.JinqJPAStreamProvider;
diff --git a/spring-jinq/src/test/java/com/baeldung/SpringContextTest.java b/spring-jinq/src/test/java/com/baeldung/SpringContextTest.java
index 1a486d1003..7c65a831c4 100644
--- a/spring-jinq/src/test/java/com/baeldung/SpringContextTest.java
+++ b/spring-jinq/src/test/java/com/baeldung/SpringContextTest.java
@@ -4,7 +4,6 @@ import com.baeldung.spring.jinq.JinqApplication;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
-import com.baeldung.spring.jinq.JinqApplication;
@SpringBootTest(classes = JinqApplication.class)
public class SpringContextTest {
diff --git a/spring-kafka-2/README.md b/spring-kafka-2/README.md
index 43b2f59147..250927314c 100644
--- a/spring-kafka-2/README.md
+++ b/spring-kafka-2/README.md
@@ -9,3 +9,4 @@ This module contains articles about Spring with Kafka
- [Understanding Kafka Topics and Partitions](https://www.baeldung.com/kafka-topics-partitions)
- [How to Subscribe a Kafka Consumer to Multiple Topics](https://www.baeldung.com/kafka-subscribe-consumer-multiple-topics)
- [Splitting Streams in Kafka](https://www.baeldung.com/kafka-splitting-streams)
+- [Manage Kafka Consumer Groups](https://www.baeldung.com/kafka-manage-consumer-groups)
diff --git a/spring-reactive-modules/spring-reactive-client/pom.xml b/spring-reactive-modules/spring-reactive-client/pom.xml
index 94134e5271..5736ce497f 100644
--- a/spring-reactive-modules/spring-reactive-client/pom.xml
+++ b/spring-reactive-modules/spring-reactive-client/pom.xml
@@ -179,7 +179,7 @@
1.0.1.RELEASE
1.0
1.1.6
- 4.0.1
+ 4.12.0
3.5.3
2.26.0
3.1.4
diff --git a/spring-security-modules/spring-security-core-2/src/main/java/com/baeldung/httpsecurityvswebsecurity/HttpSecurityConfig.java b/spring-security-modules/spring-security-core-2/src/main/java/com/baeldung/httpsecurityvswebsecurity/HttpSecurityConfig.java
index d6361255e5..414f782907 100644
--- a/spring-security-modules/spring-security-core-2/src/main/java/com/baeldung/httpsecurityvswebsecurity/HttpSecurityConfig.java
+++ b/spring-security-modules/spring-security-core-2/src/main/java/com/baeldung/httpsecurityvswebsecurity/HttpSecurityConfig.java
@@ -1,16 +1,17 @@
package com.baeldung.httpsecurityvswebsecurity;
+import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
-import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+import org.springframework.security.web.SecurityFilterChain;
@Configuration
@EnableWebSecurity
-public class HttpSecurityConfig extends WebSecurityConfigurerAdapter {
+public class HttpSecurityConfig {
- @Override
- protected void configure(HttpSecurity http) throws Exception {
+ @Bean
+ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
// Given: HttpSecurity configured
http.authorizeRequests()
@@ -27,5 +28,6 @@ public class HttpSecurityConfig extends WebSecurityConfigurerAdapter {
// When: Accessing specific URLs
// Then: Access is granted based on defined rules
+ return http.build();
}
}
diff --git a/spring-security-modules/spring-security-core-2/src/main/java/com/baeldung/httpsecurityvswebsecurity/WebSecurityConfig.java b/spring-security-modules/spring-security-core-2/src/main/java/com/baeldung/httpsecurityvswebsecurity/WebSecurityConfig.java
index 46a82918aa..ec50069ba5 100644
--- a/spring-security-modules/spring-security-core-2/src/main/java/com/baeldung/httpsecurityvswebsecurity/WebSecurityConfig.java
+++ b/spring-security-modules/spring-security-core-2/src/main/java/com/baeldung/httpsecurityvswebsecurity/WebSecurityConfig.java
@@ -1,35 +1,48 @@
package com.baeldung.httpsecurityvswebsecurity;
+import org.springframework.context.annotation.Bean;
+import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
-import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
@Configuration
-public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
+public class WebSecurityConfig {
@Autowired
private UserDetailsService userDetailsService;
- @Override
- protected void configure(AuthenticationManagerBuilder auth) throws Exception {
- auth
- .userDetailsService(userDetailsService)
- .passwordEncoder(new BCryptPasswordEncoder());
+ @Bean
+ public BCryptPasswordEncoder bCryptPasswordEncoder() {
+ return new BCryptPasswordEncoder();
}
- @Override
- protected void configure(HttpSecurity http) throws Exception {
+ @Bean
+ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
+
+ AuthenticationManagerBuilder authenticationManagerBuilder = http.getSharedObject(AuthenticationManagerBuilder.class);
+ authenticationManagerBuilder.userDetailsService(userDetailsService);
+ AuthenticationManager authenticationManager = authenticationManagerBuilder.build();
+
http.authorizeRequests()
- .antMatchers("/")
- .permitAll()
- .anyRequest()
- .authenticated()
- .and()
- .formLogin();
+ .antMatchers("/")
+ .permitAll()
+ .anyRequest()
+ .authenticated()
+ .and()
+ .formLogin().and()
+ .authenticationManager(authenticationManager)
+ .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
+
+ return http.build();
+ }
+
+ protected void configure(HttpSecurity http) throws Exception {
+
}
}
diff --git a/spring-security-modules/spring-security-oauth2/src/main/java/com/baeldung/oauth2resttemplate/SecurityConfig.java b/spring-security-modules/spring-security-oauth2/src/main/java/com/baeldung/oauth2resttemplate/SecurityConfig.java
index 1fb9a6773a..3a8e037f72 100644
--- a/spring-security-modules/spring-security-oauth2/src/main/java/com/baeldung/oauth2resttemplate/SecurityConfig.java
+++ b/spring-security-modules/spring-security-oauth2/src/main/java/com/baeldung/oauth2resttemplate/SecurityConfig.java
@@ -8,7 +8,6 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
-import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.oauth2.client.OAuth2ClientContext;
import org.springframework.security.oauth2.client.OAuth2RestTemplate;
import org.springframework.security.oauth2.client.filter.OAuth2ClientAuthenticationProcessingFilter;
diff --git a/spring-security-modules/spring-security-saml/src/main/java/com/baeldung/saml/config/WebSecurityConfig.java b/spring-security-modules/spring-security-saml/src/main/java/com/baeldung/saml/config/WebSecurityConfig.java
index 297c391823..956233dfaf 100644
--- a/spring-security-modules/spring-security-saml/src/main/java/com/baeldung/saml/config/WebSecurityConfig.java
+++ b/spring-security-modules/spring-security-saml/src/main/java/com/baeldung/saml/config/WebSecurityConfig.java
@@ -10,11 +10,9 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
-import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
-import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.saml.*;
import org.springframework.security.saml.key.KeyManager;
import org.springframework.security.saml.metadata.*;
@@ -31,7 +29,7 @@ import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled = true)
-public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
+public class WebSecurityConfig {
@Value("${saml.sp}")
private String samlAudience;
@@ -55,8 +53,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Bean
public SAMLDiscovery samlDiscovery() {
- SAMLDiscovery idpDiscovery = new SAMLDiscovery();
- return idpDiscovery;
+ return new SAMLDiscovery();
}
@Autowired
@@ -78,19 +75,19 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
}
@Bean
- public SAMLProcessingFilter samlWebSSOProcessingFilter() throws Exception {
+ public SAMLProcessingFilter samlWebSSOProcessingFilter(AuthenticationManager authenticationManager) {
SAMLProcessingFilter samlWebSSOProcessingFilter = new SAMLProcessingFilter();
- samlWebSSOProcessingFilter.setAuthenticationManager(authenticationManager());
+ samlWebSSOProcessingFilter.setAuthenticationManager(authenticationManager);
samlWebSSOProcessingFilter.setAuthenticationSuccessHandler(samlAuthSuccessHandler);
samlWebSSOProcessingFilter.setAuthenticationFailureHandler(samlAuthFailureHandler);
return samlWebSSOProcessingFilter;
}
@Bean
- public FilterChainProxy samlFilter() throws Exception {
+ public FilterChainProxy samlFilter(SAMLProcessingFilter samlProcessingFilter) throws Exception {
List chains = new ArrayList<>();
chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/SSO/**"),
- samlWebSSOProcessingFilter()));
+ samlProcessingFilter));
chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/discovery/**"),
samlDiscovery()));
chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/login/**"),
@@ -102,19 +99,13 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
return new FilterChainProxy(chains);
}
- @Bean
- @Override
- public AuthenticationManager authenticationManagerBean() throws Exception {
- return super.authenticationManagerBean();
- }
-
@Bean
public MetadataGeneratorFilter metadataGeneratorFilter() {
return new MetadataGeneratorFilter(metadataGenerator());
}
- @Override
- protected void configure(HttpSecurity http) throws Exception {
+ @Bean
+ public SecurityFilterChain filterChain(HttpSecurity http, SAMLProcessingFilter samlProcessingFilter) throws Exception {
http
.csrf()
.disable();
@@ -125,8 +116,8 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
http
.addFilterBefore(metadataGeneratorFilter(), ChannelProcessingFilter.class)
- .addFilterAfter(samlFilter(), BasicAuthenticationFilter.class)
- .addFilterBefore(samlFilter(), CsrfFilter.class);
+ .addFilterAfter(samlProcessingFilter, BasicAuthenticationFilter.class)
+ .addFilterBefore(samlProcessingFilter, CsrfFilter.class);
http
.authorizeRequests()
@@ -142,11 +133,10 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
e.printStackTrace();
}
});
- }
- @Override
- protected void configure(AuthenticationManagerBuilder auth) throws Exception {
- auth.authenticationProvider(samlAuthenticationProvider);
+ http.authenticationProvider(samlAuthenticationProvider);
+
+ return http.build();
}
}
diff --git a/spring-security-modules/spring-security-web-persistent-login/src/main/java/com/baeldung/spring/SecurityConfig.java b/spring-security-modules/spring-security-web-persistent-login/src/main/java/com/baeldung/spring/SecurityConfig.java
index d3cfff81cb..0a9c717f5a 100644
--- a/spring-security-modules/spring-security-web-persistent-login/src/main/java/com/baeldung/spring/SecurityConfig.java
+++ b/spring-security-modules/spring-security-web-persistent-login/src/main/java/com/baeldung/spring/SecurityConfig.java
@@ -3,7 +3,6 @@ package com.baeldung.spring;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
-import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
/**
* Spring Security Configuration.
@@ -11,7 +10,7 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur
@Configuration
@EnableWebSecurity
@ImportResource({ "classpath:webSecurityConfig.xml" })
-public class SecurityConfig extends WebSecurityConfigurerAdapter {
+public class SecurityConfig {
public SecurityConfig() {
super();
diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/pom.xml b/spring-swagger-codegen/spring-openapi-generator-api-client/pom.xml
index ee2c86238a..1e3b93ae42 100644
--- a/spring-swagger-codegen/spring-openapi-generator-api-client/pom.xml
+++ b/spring-swagger-codegen/spring-openapi-generator-api-client/pom.xml
@@ -276,7 +276,7 @@
2.2
1.10
3.6.1
- 2.10.4
+ 3.6.2
2.2.1
1.5
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 35f4978411..af12f9cef0 100644
--- a/spring-swagger-codegen/spring-swagger-codegen-api-client/pom.xml
+++ b/spring-swagger-codegen/spring-swagger-codegen-api-client/pom.xml
@@ -196,7 +196,7 @@
2.2
1.5
2.2.1
- 2.10.4
+ 3.6.2
1.10
diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml
index 2be896ad83..87bcfaa203 100644
--- a/spring-web-modules/pom.xml
+++ b/spring-web-modules/pom.xml
@@ -44,6 +44,7 @@
spring-rest-simple
spring-rest-testing
spring-resttemplate
+ spring-resttemplate-1
spring-resttemplate-2
spring-resttemplate-3
spring-session
diff --git a/spring-web-modules/spring-mvc-basics-2/pom.xml b/spring-web-modules/spring-mvc-basics-2/pom.xml
index 613e42dee3..32cf3c9e9f 100644
--- a/spring-web-modules/spring-mvc-basics-2/pom.xml
+++ b/spring-web-modules/spring-mvc-basics-2/pom.xml
@@ -150,7 +150,7 @@
8.0.1.Final
enter-location-of-server
- 3.0.11.RELEASE
+ 3.1.2.RELEASE
2.4.12
2.3.27-incubating
1.2.5
diff --git a/spring-web-modules/spring-mvc-java-2/README.md b/spring-web-modules/spring-mvc-java-2/README.md
index 74d8cca312..1f8231bada 100644
--- a/spring-web-modules/spring-mvc-java-2/README.md
+++ b/spring-web-modules/spring-mvc-java-2/README.md
@@ -1,9 +1,7 @@
### Relevant Articles:
- [Cache Headers in Spring MVC](https://www.baeldung.com/spring-mvc-cache-headers)
-- [Working with Date Parameters in Spring](https://www.baeldung.com/spring-date-parameters)
- [Spring MVC @PathVariable with a dot (.) gets truncated](https://www.baeldung.com/spring-mvc-pathvariable-dot)
- [A Quick Guide to Spring MVC Matrix Variables](https://www.baeldung.com/spring-mvc-matrix-variables)
- [Converting a Spring MultipartFile to a File](https://www.baeldung.com/spring-multipartfile-to-file)
- [Testing a Spring Multipart POST Request](https://www.baeldung.com/spring-multipart-post-request-test)
-- [Spring @PathVariable Annotation](https://www.baeldung.com/spring-pathvariable)
diff --git a/spring-web-modules/spring-mvc-java/README.md b/spring-web-modules/spring-mvc-java/README.md
index afd1aea3bf..656e415f6a 100644
--- a/spring-web-modules/spring-mvc-java/README.md
+++ b/spring-web-modules/spring-mvc-java/README.md
@@ -14,3 +14,6 @@ The "REST With Spring" Classes: https://bit.ly/restwithspring
- [web.xml vs Initializer with Spring](https://www.baeldung.com/spring-xml-vs-java-config)
- [A Java Web Application Without a web.xml](https://www.baeldung.com/java-web-app-without-web-xml)
- [Accessing Spring MVC Model Objects in JavaScript](https://www.baeldung.com/spring-mvc-model-objects-js)
+- [Spring @PathVariable Annotation](https://www.baeldung.com/spring-pathvariable)
+- [Working with Date Parameters in Spring](https://www.baeldung.com/spring-date-parameters)
+
diff --git a/spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/datetime/DateTimeConfig.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/datetime/DateTimeConfig.java
similarity index 100%
rename from spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/datetime/DateTimeConfig.java
rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/datetime/DateTimeConfig.java
diff --git a/spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/datetime/DateTimeController.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/datetime/DateTimeController.java
similarity index 100%
rename from spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/datetime/DateTimeController.java
rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/datetime/DateTimeController.java
diff --git a/spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/pathvariable/PathVariableAnnotationController.java b/spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/pathvariable/PathVariableAnnotationController.java
similarity index 100%
rename from spring-web-modules/spring-mvc-java-2/src/main/java/com/baeldung/pathvariable/PathVariableAnnotationController.java
rename to spring-web-modules/spring-mvc-java/src/main/java/com/baeldung/pathvariable/PathVariableAnnotationController.java
diff --git a/spring-web-modules/spring-rest-http-2/pom.xml b/spring-web-modules/spring-rest-http-2/pom.xml
index bcacdbbdb1..c6c8cd2010 100644
--- a/spring-web-modules/spring-rest-http-2/pom.xml
+++ b/spring-web-modules/spring-rest-http-2/pom.xml
@@ -51,7 +51,7 @@
2.9.2
- 1.6.1
+ 2.1.0
1.7.0
diff --git a/spring-web-modules/spring-rest-simple/pom.xml b/spring-web-modules/spring-rest-simple/pom.xml
index 2764ac8393..089c5e411f 100644
--- a/spring-web-modules/spring-rest-simple/pom.xml
+++ b/spring-web-modules/spring-rest-simple/pom.xml
@@ -292,7 +292,7 @@
1.6.0
3.0.4
- 3.4.1
+ 4.12.0
2.2.0
diff --git a/spring-web-modules/spring-resttemplate-1/README.md b/spring-web-modules/spring-resttemplate-1/README.md
new file mode 100644
index 0000000000..d5cf69e86a
--- /dev/null
+++ b/spring-web-modules/spring-resttemplate-1/README.md
@@ -0,0 +1,7 @@
+## Spring RestTemplate
+
+This module contains articles about Spring RestTemplate
+
+### Relevant Articles:
+- [RestTemplate Post Request with JSON](https://www.baeldung.com/spring-resttemplate-post-json)
+- [Get and Post Lists of Objects with RestTemplate](https://www.baeldung.com/spring-rest-template-list)
diff --git a/spring-web-modules/spring-resttemplate-1/pom.xml b/spring-web-modules/spring-resttemplate-1/pom.xml
new file mode 100644
index 0000000000..209c941ede
--- /dev/null
+++ b/spring-web-modules/spring-resttemplate-1/pom.xml
@@ -0,0 +1,30 @@
+
+
+ 4.0.0
+ spring-resttemplate-1
+ 0.1-SNAPSHOT
+ spring-resttemplate-1
+ war
+
+
+ com.baeldung
+ parent-boot-2
+ 0.0.1-SNAPSHOT
+ ../../parent-boot-2
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+
+
+
+
\ No newline at end of file
diff --git a/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/RestTemplateApplication.java b/spring-web-modules/spring-resttemplate-1/src/main/java/com/baeldung/resttemplate/RestTemplateApplication.java
similarity index 100%
rename from spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/RestTemplateApplication.java
rename to spring-web-modules/spring-resttemplate-1/src/main/java/com/baeldung/resttemplate/RestTemplateApplication.java
diff --git a/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/RestTemplateConfigurationApplication.java b/spring-web-modules/spring-resttemplate-1/src/main/java/com/baeldung/resttemplate/RestTemplateConfigurationApplication.java
similarity index 100%
rename from spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/RestTemplateConfigurationApplication.java
rename to spring-web-modules/spring-resttemplate-1/src/main/java/com/baeldung/resttemplate/RestTemplateConfigurationApplication.java
diff --git a/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/EmployeeApplication.java b/spring-web-modules/spring-resttemplate-1/src/main/java/com/baeldung/resttemplate/lists/EmployeeApplication.java
similarity index 100%
rename from spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/EmployeeApplication.java
rename to spring-web-modules/spring-resttemplate-1/src/main/java/com/baeldung/resttemplate/lists/EmployeeApplication.java
diff --git a/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/client/EmployeeClient.java b/spring-web-modules/spring-resttemplate-1/src/main/java/com/baeldung/resttemplate/lists/client/EmployeeClient.java
similarity index 99%
rename from spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/client/EmployeeClient.java
rename to spring-web-modules/spring-resttemplate-1/src/main/java/com/baeldung/resttemplate/lists/client/EmployeeClient.java
index 49e375f9cc..7fa0d55690 100644
--- a/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/client/EmployeeClient.java
+++ b/spring-web-modules/spring-resttemplate-1/src/main/java/com/baeldung/resttemplate/lists/client/EmployeeClient.java
@@ -1,16 +1,17 @@
package com.baeldung.resttemplate.lists.client;
-import com.baeldung.resttemplate.lists.dto.Employee;
-import com.baeldung.resttemplate.lists.dto.EmployeeList;
+import static java.util.Arrays.asList;
+
+import java.util.ArrayList;
+import java.util.List;
+
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
-import java.util.ArrayList;
-import java.util.List;
-
-import static java.util.Arrays.asList;
+import com.baeldung.resttemplate.lists.dto.Employee;
+import com.baeldung.resttemplate.lists.dto.EmployeeList;
/**
* Application that shows how to use Lists with RestTemplate.
diff --git a/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/controller/EmployeeResource.java b/spring-web-modules/spring-resttemplate-1/src/main/java/com/baeldung/resttemplate/lists/controller/EmployeeResource.java
similarity index 100%
rename from spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/controller/EmployeeResource.java
rename to spring-web-modules/spring-resttemplate-1/src/main/java/com/baeldung/resttemplate/lists/controller/EmployeeResource.java
index 8a4d510f63..1cd68f89b9 100644
--- a/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/controller/EmployeeResource.java
+++ b/spring-web-modules/spring-resttemplate-1/src/main/java/com/baeldung/resttemplate/lists/controller/EmployeeResource.java
@@ -1,5 +1,7 @@
package com.baeldung.resttemplate.lists.controller;
+import java.util.List;
+
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -10,8 +12,6 @@ import com.baeldung.resttemplate.lists.dto.Employee;
import com.baeldung.resttemplate.lists.dto.EmployeeList;
import com.baeldung.resttemplate.lists.service.EmployeeService;
-import java.util.List;
-
@RestController
@RequestMapping("/employees")
public class EmployeeResource
diff --git a/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/dto/Employee.java b/spring-web-modules/spring-resttemplate-1/src/main/java/com/baeldung/resttemplate/lists/dto/Employee.java
similarity index 100%
rename from spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/dto/Employee.java
rename to spring-web-modules/spring-resttemplate-1/src/main/java/com/baeldung/resttemplate/lists/dto/Employee.java
diff --git a/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/dto/EmployeeList.java b/spring-web-modules/spring-resttemplate-1/src/main/java/com/baeldung/resttemplate/lists/dto/EmployeeList.java
similarity index 100%
rename from spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/dto/EmployeeList.java
rename to spring-web-modules/spring-resttemplate-1/src/main/java/com/baeldung/resttemplate/lists/dto/EmployeeList.java
diff --git a/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/service/EmployeeService.java b/spring-web-modules/spring-resttemplate-1/src/main/java/com/baeldung/resttemplate/lists/service/EmployeeService.java
similarity index 100%
rename from spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/service/EmployeeService.java
rename to spring-web-modules/spring-resttemplate-1/src/main/java/com/baeldung/resttemplate/lists/service/EmployeeService.java
index 8a1773483a..a9ea3f373f 100644
--- a/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/lists/service/EmployeeService.java
+++ b/spring-web-modules/spring-resttemplate-1/src/main/java/com/baeldung/resttemplate/lists/service/EmployeeService.java
@@ -1,12 +1,12 @@
package com.baeldung.resttemplate.lists.service;
+import java.util.ArrayList;
+import java.util.List;
+
import org.springframework.stereotype.Service;
import com.baeldung.resttemplate.lists.dto.Employee;
-import java.util.ArrayList;
-import java.util.List;
-
@Service("EmployeeListService")
public class EmployeeService
{
diff --git a/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/web/controller/PersonAPI.java b/spring-web-modules/spring-resttemplate-1/src/main/java/com/baeldung/resttemplate/web/controller/PersonAPI.java
similarity index 100%
rename from spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/web/controller/PersonAPI.java
rename to spring-web-modules/spring-resttemplate-1/src/main/java/com/baeldung/resttemplate/web/controller/PersonAPI.java
diff --git a/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/web/dto/Person.java b/spring-web-modules/spring-resttemplate-1/src/main/java/com/baeldung/resttemplate/web/dto/Person.java
similarity index 100%
rename from spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/web/dto/Person.java
rename to spring-web-modules/spring-resttemplate-1/src/main/java/com/baeldung/resttemplate/web/dto/Person.java
diff --git a/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/web/service/PersonService.java b/spring-web-modules/spring-resttemplate-1/src/main/java/com/baeldung/resttemplate/web/service/PersonService.java
similarity index 100%
rename from spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/web/service/PersonService.java
rename to spring-web-modules/spring-resttemplate-1/src/main/java/com/baeldung/resttemplate/web/service/PersonService.java
diff --git a/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/web/service/PersonServiceImpl.java b/spring-web-modules/spring-resttemplate-1/src/main/java/com/baeldung/resttemplate/web/service/PersonServiceImpl.java
similarity index 100%
rename from spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/web/service/PersonServiceImpl.java
rename to spring-web-modules/spring-resttemplate-1/src/main/java/com/baeldung/resttemplate/web/service/PersonServiceImpl.java
diff --git a/spring-web-modules/spring-resttemplate-1/src/main/resources/application.properties b/spring-web-modules/spring-resttemplate-1/src/main/resources/application.properties
new file mode 100644
index 0000000000..ea4f7c866d
--- /dev/null
+++ b/spring-web-modules/spring-resttemplate-1/src/main/resources/application.properties
@@ -0,0 +1,2 @@
+server.port=8080
+server.servlet.context-path=/spring-rest
\ No newline at end of file
diff --git a/spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/postjson/PersonAPILiveTest.java b/spring-web-modules/spring-resttemplate-1/src/test/java/com/baeldung/resttemplate/postjson/PersonAPILiveTest.java
similarity index 100%
rename from spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/postjson/PersonAPILiveTest.java
rename to spring-web-modules/spring-resttemplate-1/src/test/java/com/baeldung/resttemplate/postjson/PersonAPILiveTest.java
diff --git a/spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/postjson/RestTemplatePostRequestEncodingLiveTest.java b/spring-web-modules/spring-resttemplate-1/src/test/java/com/baeldung/resttemplate/postjson/RestTemplatePostRequestEncodingLiveTest.java
similarity index 100%
rename from spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/postjson/RestTemplatePostRequestEncodingLiveTest.java
rename to spring-web-modules/spring-resttemplate-1/src/test/java/com/baeldung/resttemplate/postjson/RestTemplatePostRequestEncodingLiveTest.java
diff --git a/spring-web-modules/spring-resttemplate-1/src/test/resources/application.properties b/spring-web-modules/spring-resttemplate-1/src/test/resources/application.properties
new file mode 100644
index 0000000000..286ea95a4f
--- /dev/null
+++ b/spring-web-modules/spring-resttemplate-1/src/test/resources/application.properties
@@ -0,0 +1,5 @@
+logging.level.org.springframework.web.client.RestTemplate=DEBUG
+logging.level.com.baeldung.resttemplate.logging=DEBUG
+logging.level.org.apache.http=DEBUG
+logging.level.httpclient.wire=DEBUG
+logging.pattern.console=%20logger{20} - %msg%n
diff --git a/spring-web-modules/spring-resttemplate-1/src/test/resources/logback-test.xml b/spring-web-modules/spring-resttemplate-1/src/test/resources/logback-test.xml
new file mode 100644
index 0000000000..8d4771e308
--- /dev/null
+++ b/spring-web-modules/spring-resttemplate-1/src/test/resources/logback-test.xml
@@ -0,0 +1,12 @@
+
+
+
+
+ [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/spring-web-modules/spring-resttemplate-2/README.md b/spring-web-modules/spring-resttemplate-2/README.md
index ace7ae817b..ad2a671040 100644
--- a/spring-web-modules/spring-resttemplate-2/README.md
+++ b/spring-web-modules/spring-resttemplate-2/README.md
@@ -7,7 +7,6 @@ This module contains articles about Spring RestTemplate
- [Spring RestTemplate Request/Response Logging](https://www.baeldung.com/spring-resttemplate-logging)
- [Proxies With RestTemplate](https://www.baeldung.com/java-resttemplate-proxy)
- [A Custom Media Type for a Spring REST API](https://www.baeldung.com/spring-rest-custom-media-type)
-- [RestTemplate Post Request with JSON](https://www.baeldung.com/spring-resttemplate-post-json)
- [How to Compress Requests Using the Spring RestTemplate](https://www.baeldung.com/spring-resttemplate-compressing-requests)
- [Get list of JSON objects with Spring RestTemplate](https://www.baeldung.com/spring-resttemplate-json-list)
- [Spring RestTemplate Exception: “Not enough variables available to expand”](https://www.baeldung.com/spring-not-enough-variables-available)
diff --git a/spring-web-modules/spring-resttemplate-3/README.md b/spring-web-modules/spring-resttemplate-3/README.md
index f3cfb1d671..14aaf77b9e 100644
--- a/spring-web-modules/spring-resttemplate-3/README.md
+++ b/spring-web-modules/spring-resttemplate-3/README.md
@@ -7,7 +7,6 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
### Relevant Articles:
- [Uploading MultipartFile with Spring RestTemplate](https://www.baeldung.com/spring-rest-template-multipart-upload)
-- [Get and Post Lists of Objects with RestTemplate](https://www.baeldung.com/spring-rest-template-list)
- [Download a Large File Through a Spring RestTemplate](https://www.baeldung.com/spring-resttemplate-download-large-file)
- [Access HTTPS REST Service Using Spring RestTemplate](https://www.baeldung.com/spring-resttemplate-secure-https-service)
- [Encoding of URI Variables on RestTemplate](https://www.baeldung.com/spring-resttemplate-uri-variables-encode)
diff --git a/spring-web-modules/spring-resttemplate/pom.xml b/spring-web-modules/spring-resttemplate/pom.xml
index 4abaac5628..5cf1476f87 100644
--- a/spring-web-modules/spring-resttemplate/pom.xml
+++ b/spring-web-modules/spring-resttemplate/pom.xml
@@ -274,7 +274,7 @@
1.6.1
3.0.4
- 3.4.1
+ 4.12.0
3.6.3
1.8
1.8
diff --git a/spring-web-modules/spring-thymeleaf-5/pom.xml b/spring-web-modules/spring-thymeleaf-5/pom.xml
index 2d178bd933..e6b0511ce5 100644
--- a/spring-web-modules/spring-thymeleaf-5/pom.xml
+++ b/spring-web-modules/spring-thymeleaf-5/pom.xml
@@ -135,7 +135,7 @@
2.3.2.RELEASE
- 3.0.11.RELEASE
+ 3.1.2.RELEASE
3.0.4.RELEASE
2.4.1
2.0.1.Final
diff --git a/spring-web-modules/spring-thymeleaf/pom.xml b/spring-web-modules/spring-thymeleaf/pom.xml
index ce0c0a7e21..ca94d4581e 100644
--- a/spring-web-modules/spring-thymeleaf/pom.xml
+++ b/spring-web-modules/spring-thymeleaf/pom.xml
@@ -136,7 +136,7 @@
2.3.2.RELEASE
- 3.0.11.RELEASE
+ 3.1.2.RELEASE
3.0.4.RELEASE
2.4.1
2.0.1.Final
diff --git a/spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebMVCSecurity.java b/spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebMVCSecurity.java
index ea51ca3cd9..074cc20be1 100644
--- a/spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebMVCSecurity.java
+++ b/spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebMVCSecurity.java
@@ -2,42 +2,37 @@ package com.baeldung.thymeleaf.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import org.springframework.security.authentication.AuthenticationManager;
-import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
-import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
-import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
+import org.springframework.security.core.userdetails.User;
+import org.springframework.security.core.userdetails.UserDetails;
+import org.springframework.security.provisioning.InMemoryUserDetailsManager;
+import org.springframework.security.web.SecurityFilterChain;
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true)
-public class WebMVCSecurity extends WebSecurityConfigurerAdapter {
+public class WebMVCSecurity {
@Bean
- @Override
- public AuthenticationManager authenticationManagerBean() throws Exception {
- return super.authenticationManagerBean();
+ public InMemoryUserDetailsManager userDetailsService() {
+ UserDetails user = User.withUsername("user1")
+ .password("{noop}user1Pass")
+ .authorities("USER")
+ .build();
+ return new InMemoryUserDetailsManager(user);
}
- public WebMVCSecurity() {
- super();
+ @Bean
+ public WebSecurityCustomizer webSecurityCustomizer() {
+ return (web) -> web.ignoring().antMatchers("/resources/**");
}
- @Override
- protected void configure(final AuthenticationManagerBuilder auth) throws Exception {
- auth.inMemoryAuthentication().withUser("user1").password("{noop}user1Pass").authorities("ROLE_USER");
- }
-
- @Override
- public void configure(final WebSecurity web) throws Exception {
- web.ignoring().antMatchers("/resources/**");
- }
-
- @Override
- protected void configure(final HttpSecurity http) throws Exception {
- http.authorizeRequests().anyRequest().authenticated().and().httpBasic();
+ @Bean
+ public SecurityFilterChain filterChain(final HttpSecurity http) throws Exception {
+ return http.authorizeRequests().anyRequest().authenticated().and().httpBasic().and().build();
}
}
diff --git a/static-analysis/error-prone-project/.mvn/jvm.config b/static-analysis/error-prone-project/.mvn/jvm.config
new file mode 100644
index 0000000000..32599cefea
--- /dev/null
+++ b/static-analysis/error-prone-project/.mvn/jvm.config
@@ -0,0 +1,10 @@
+--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
+--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
+--add-exports jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED
+--add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED
+--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
+--add-exports jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED
+--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
+--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
+--add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
+--add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED
diff --git a/static-analysis/error-prone-project/pom.xml b/static-analysis/error-prone-project/pom.xml
new file mode 100644
index 0000000000..59f7bb7270
--- /dev/null
+++ b/static-analysis/error-prone-project/pom.xml
@@ -0,0 +1,61 @@
+
+
+ 4.0.0
+
+ com.baeldung
+ static-analysis
+ 1.0-SNAPSHOT
+
+
+ error-prone-project
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ ${maven-compiler-plugin.version}
+
+ 17
+ UTF-8
+ true
+
+ -XDcompilePolicy=simple
+ -Xplugin:ErrorProne
+ -J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
+ -J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
+ -J--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED
+ -J--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED
+ -J--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
+ -J--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED
+ -J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
+ -J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
+ -J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
+ -J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED
+
+
+
+ com.google.errorprone
+ error_prone_core
+ ${error-prone.version}
+
+
+ com.baeldung
+ my-bugchecker-plugin
+ 1.0-SNAPSHOT
+
+
+
+
+
+
+
+
+ 17
+ 17
+ UTF-8
+
+
+
diff --git a/static-analysis/error-prone-project/src/main/java/com/baeldung/BuggyClass.java b/static-analysis/error-prone-project/src/main/java/com/baeldung/BuggyClass.java
new file mode 100644
index 0000000000..dda432ad48
--- /dev/null
+++ b/static-analysis/error-prone-project/src/main/java/com/baeldung/BuggyClass.java
@@ -0,0 +1,12 @@
+package com.baeldung;
+
+public class BuggyClass {
+ public static void main(String[] args) {
+ if (args.length == 0 || args[0] != null) {
+ new IllegalArgumentException();
+ }
+ }
+
+ public void emptyMethod() {
+ }
+}
diff --git a/static-analysis/error-prone-project/src/main/java/com/baeldung/ClassWithEmptyMethod.java b/static-analysis/error-prone-project/src/main/java/com/baeldung/ClassWithEmptyMethod.java
new file mode 100644
index 0000000000..cc791ecdd4
--- /dev/null
+++ b/static-analysis/error-prone-project/src/main/java/com/baeldung/ClassWithEmptyMethod.java
@@ -0,0 +1,6 @@
+package com.baeldung;
+
+public class ClassWithEmptyMethod {
+ public void theEmptyMethod() {
+ }
+}
diff --git a/static-analysis/my-bugchecker-plugin/pom.xml b/static-analysis/my-bugchecker-plugin/pom.xml
new file mode 100644
index 0000000000..cbe16b0a14
--- /dev/null
+++ b/static-analysis/my-bugchecker-plugin/pom.xml
@@ -0,0 +1,56 @@
+
+
+ 4.0.0
+
+ com.baeldung
+ static-analysis
+ 1.0-SNAPSHOT
+
+ jar
+ my-bugchecker-plugin
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ ${maven-compiler-plugin.version}
+
+
+
+ com.google.auto.service
+ auto-service
+ ${google-auto-service.version}
+
+
+
+
+
+
+
+
+ com.google.errorprone
+ error_prone_annotation
+ ${error-prone.version}
+
+
+ com.google.errorprone
+ error_prone_check_api
+ ${error-prone.version}
+
+
+ com.google.auto.service
+ auto-service-annotations
+ ${google-auto-service.version}
+
+
+
+
+ 17
+ 17
+ UTF-8
+
+
+
diff --git a/static-analysis/my-bugchecker-plugin/src/main/java/com/baeldung/EmptyMethodChecker.java b/static-analysis/my-bugchecker-plugin/src/main/java/com/baeldung/EmptyMethodChecker.java
new file mode 100644
index 0000000000..f31913c086
--- /dev/null
+++ b/static-analysis/my-bugchecker-plugin/src/main/java/com/baeldung/EmptyMethodChecker.java
@@ -0,0 +1,24 @@
+package com.baeldung;
+
+import com.google.auto.service.AutoService;
+import com.google.errorprone.BugPattern;
+import com.google.errorprone.VisitorState;
+import com.google.errorprone.bugpatterns.BugChecker;
+import com.google.errorprone.fixes.SuggestedFix;
+import com.google.errorprone.matchers.Description;
+import com.sun.source.tree.MethodTree;
+
+
+@AutoService(BugChecker.class)
+@BugPattern(name = "EmptyMethodCheck", summary = "Empty methods should be deleted", severity = BugPattern.SeverityLevel.ERROR)
+public class EmptyMethodChecker extends BugChecker implements BugChecker.MethodTreeMatcher {
+ @Override
+ public Description matchMethod(MethodTree methodTree, VisitorState visitorState) {
+ if (methodTree.getBody()
+ .getStatements()
+ .isEmpty()) {
+ return describeMatch(methodTree, SuggestedFix.delete(methodTree));
+ }
+ return Description.NO_MATCH;
+ }
+}
diff --git a/static-analysis/pmd/pom.xml b/static-analysis/pmd/pom.xml
new file mode 100644
index 0000000000..31914fe9f0
--- /dev/null
+++ b/static-analysis/pmd/pom.xml
@@ -0,0 +1,20 @@
+
+
+ 4.0.0
+
+ com.baeldung
+ static-analysis
+ 1.0-SNAPSHOT
+
+
+ pmd
+
+
+ 17
+ 17
+ UTF-8
+
+
+
diff --git a/static-analysis/src/main/java/com/baeldung/pmd/Cnt.java b/static-analysis/pmd/src/main/java/com/baeldung/pmd/Cnt.java
similarity index 100%
rename from static-analysis/src/main/java/com/baeldung/pmd/Cnt.java
rename to static-analysis/pmd/src/main/java/com/baeldung/pmd/Cnt.java
diff --git a/static-analysis/src/main/resources/customruleset.xml b/static-analysis/pmd/src/main/resources/customruleset.xml
similarity index 97%
rename from static-analysis/src/main/resources/customruleset.xml
rename to static-analysis/pmd/src/main/resources/customruleset.xml
index e0a009dd4a..6b1a80334d 100644
--- a/static-analysis/src/main/resources/customruleset.xml
+++ b/static-analysis/pmd/src/main/resources/customruleset.xml
@@ -1,37 +1,37 @@
-
-
-
-
- This ruleset checks my code for bad stuff
-
-
-
-
-
-
-
-
-
-
-
-
-
- 2
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+ This ruleset checks my code for bad stuff
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/static-analysis/src/main/resources/logback.xml b/static-analysis/pmd/src/main/resources/logback.xml
similarity index 100%
rename from static-analysis/src/main/resources/logback.xml
rename to static-analysis/pmd/src/main/resources/logback.xml
diff --git a/static-analysis/src/test/java/com/baeldung/pmd/CntUnitTest.java b/static-analysis/pmd/src/test/java/com/baeldung/pmd/CntUnitTest.java
similarity index 100%
rename from static-analysis/src/test/java/com/baeldung/pmd/CntUnitTest.java
rename to static-analysis/pmd/src/test/java/com/baeldung/pmd/CntUnitTest.java
diff --git a/static-analysis/pom.xml b/static-analysis/pom.xml
index eedf5ba724..176f3dc092 100644
--- a/static-analysis/pom.xml
+++ b/static-analysis/pom.xml
@@ -6,6 +6,7 @@
static-analysis
1.0-SNAPSHOT
static-analysis
+ pom
com.baeldung
@@ -29,4 +30,15 @@
-
\ No newline at end of file
+
+ pmd
+ my-bugchecker-plugin
+ error-prone-project
+
+
+
+ 2.23.0
+ 1.0.1
+
+
+
diff --git a/testing-modules/testing-assertions/README.md b/testing-modules/testing-assertions/README.md
index 8f94277791..3e529bc1d3 100644
--- a/testing-modules/testing-assertions/README.md
+++ b/testing-modules/testing-assertions/README.md
@@ -6,3 +6,4 @@
- [Assert That an Object Is From a Specific Type](https://www.baeldung.com/java-assert-object-of-type)
- [Asserting Equality on Two Classes Without an equals() Method](https://www.baeldung.com/java-assert-equality-no-equals)
- [Assert Regex Matches in JUnit](https://www.baeldung.com/junit-assert-regex-matches)
+- [Asserting Nested Map With JUnit](https://www.baeldung.com/junit-assert-nested-map)
diff --git a/web-modules/jooby/pom.xml b/web-modules/jooby/pom.xml
index 238f17571f..998ceaef4e 100644
--- a/web-modules/jooby/pom.xml
+++ b/web-modules/jooby/pom.xml
@@ -77,7 +77,7 @@
com.baeldung.jooby.App
3.2.4
3.8.1
- 4.9.1
+ 4.12.0
\ No newline at end of file
diff --git a/xml-2/README.md b/xml-2/README.md
index e9c1a07586..a6762f2840 100644
--- a/xml-2/README.md
+++ b/xml-2/README.md
@@ -9,3 +9,4 @@ This module contains articles about eXtensible Markup Language (XML)
- [Converting JSON to XML in Java](https://www.baeldung.com/java-convert-json-to-xml)
- [Convert an XML Object to a String in Java](https://www.baeldung.com/java-convert-xml-object-string)
- [Convert String Containing XML to org.w3c.dom.Document](https://www.baeldung.com/java-convert-string-xml-dom)
+- [How to Parse XML to HashMap in Java](https://www.baeldung.com/java-xml-read-into-hashmap)
diff --git a/xml/pom.xml b/xml/pom.xml
index b56b919914..785634e265 100644
--- a/xml/pom.xml
+++ b/xml/pom.xml
@@ -372,7 +372,7 @@
0.9.6
1.3.1
- 1.14.3
+ 1.16.2
2.25
3.4
6.7.0
diff --git a/xml/src/main/java/com/baeldung/xml/xml2csv/Xml2CsvExample.java b/xml/src/main/java/com/baeldung/xml/xml2csv/Xml2CsvExample.java
index 99e5c7c0cb..84098b33f8 100644
--- a/xml/src/main/java/com/baeldung/xml/xml2csv/Xml2CsvExample.java
+++ b/xml/src/main/java/com/baeldung/xml/xml2csv/Xml2CsvExample.java
@@ -40,7 +40,7 @@ public class Xml2CsvExample {
protected static void convertXml2CsvXslt(String xslPath, String xmlPath, String csvPath) throws IOException, TransformerException {
StreamSource styleSource = new StreamSource(new File(xslPath));
Transformer transformer = TransformerFactory.newInstance()
- .newTransformer(styleSource);
+ .newTransformer(styleSource);
Source source = new StreamSource(new File(xmlPath));
Result outputTarget = new StreamResult(new File(csvPath));
transformer.transform(source, outputTarget);
@@ -68,26 +68,26 @@ public class Xml2CsvExample {
if ("Bookstore".equals(currentElement)) {
bookstoreInfo.setLength(0);
bookstoreInfo.append(reader.getAttributeValue(null, "id"))
- .append(",");
+ .append(",");
}
if ("Book".equals(currentElement)) {
csvRow.append(bookstoreInfo)
- .append(reader.getAttributeValue(null, "id"))
- .append(",")
- .append(reader.getAttributeValue(null, "category"))
- .append(",");
+ .append(reader.getAttributeValue(null, "id"))
+ .append(",")
+ .append(reader.getAttributeValue(null, "category"))
+ .append(",");
}
if ("Author".equals(currentElement)) {
csvRow.append(reader.getAttributeValue(null, "id"))
- .append(",");
+ .append(",");
}
break;
case XMLStreamConstants.CHARACTERS:
if (!reader.isWhiteSpace()) {
csvRow.append(reader.getText()
- .trim())
- .append(",");
+ .trim())
+ .append(",");
}
break;
diff --git a/xml/src/test/java/com/baeldung/xml/xml2csv/Xml2CsvExampleUnitTest.java b/xml/src/test/java/com/baeldung/xml/xml2csv/Xml2CsvExampleUnitTest.java
index 3fa44b427c..181d284b2d 100644
--- a/xml/src/test/java/com/baeldung/xml/xml2csv/Xml2CsvExampleUnitTest.java
+++ b/xml/src/test/java/com/baeldung/xml/xml2csv/Xml2CsvExampleUnitTest.java
@@ -91,7 +91,7 @@ public class Xml2CsvExampleUnitTest {
Xml2CsvExample.convertXml2CsvXslt(STYLE_XSL, DATA_XML, TEMP_OUTPUT_CSV);
File csvFile = new File(TEMP_OUTPUT_CSV);
- try(BufferedReader reader = new BufferedReader(new FileReader(csvFile))) {
+ try (BufferedReader reader = new BufferedReader(new FileReader(csvFile))) {
String line;
boolean isFirstLine = true;
while ((line = reader.readLine()) != null) {
@@ -113,7 +113,7 @@ public class Xml2CsvExampleUnitTest {
Xml2CsvExample.convertXml2CsvStax(DATA_XML, TEMP_OUTPUT_CSV);
File csvFile = new File(TEMP_OUTPUT_CSV);
- try(BufferedReader reader = new BufferedReader(new FileReader(csvFile))) {
+ try (BufferedReader reader = new BufferedReader(new FileReader(csvFile))) {
String line;
boolean isFirstLine = true;
while ((line = reader.readLine()) != null) {