diff --git a/apache-poi-3/pom.xml b/apache-poi-3/pom.xml new file mode 100644 index 0000000000..5031e1c5c7 --- /dev/null +++ b/apache-poi-3/pom.xml @@ -0,0 +1,33 @@ + + + 4.0.0 + apache-poi-3 + 0.0.1-SNAPSHOT + apache-poi-3 + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + + + org.apache.poi + poi-ooxml + ${poi.version} + + + org.apache.poi + poi-scratchpad + ${poi.version} + + + + + 5.2.3 + + + \ No newline at end of file diff --git a/apache-poi-3/src/test/java/com/baeldung/poi/excel/expandcolumn/ExpandColumnUnitTest.java b/apache-poi-3/src/test/java/com/baeldung/poi/excel/expandcolumn/ExpandColumnUnitTest.java new file mode 100644 index 0000000000..04d0aef211 --- /dev/null +++ b/apache-poi-3/src/test/java/com/baeldung/poi/excel/expandcolumn/ExpandColumnUnitTest.java @@ -0,0 +1,70 @@ +package com.baeldung.poi.excel.expandcolumn; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; + +import java.io.IOException; + +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class ExpandColumnUnitTest { + + private Workbook workbook; + private Sheet sheet; + + @BeforeEach + void prepareSpreadsheet() { + workbook = new XSSFWorkbook(); + sheet = workbook.createSheet(); + + Row headerRow = sheet.createRow(0); + Cell headerCell1 = headerRow.createCell(0); + headerCell1.setCellValue("Full Name"); + Cell headerCell2 = headerRow.createCell(1); + headerCell2.setCellValue("Abbreviation"); + + Row dataRow = sheet.createRow(1); + Cell dataCell1 = dataRow.createCell(0); + dataCell1.setCellValue("Java Virtual Machine"); + Cell dataCell2 = dataRow.createCell(1); + dataCell2.setCellValue("JVM"); + + dataRow = sheet.createRow(2); + dataCell1 = dataRow.createCell(0); + dataCell1.setCellValue("Java Runtime Environment"); + dataCell2 = dataRow.createCell(1); + dataCell2.setCellValue("JRE"); + } + + @Test + void whenSetColumnWidth_thenColumnSetToTheSpecifiedWidth() { + + Row row = sheet.getRow(2); + String cellValue = row.getCell(0).getStringCellValue(); + int targetWidth = cellValue.length() * 256; + + sheet.setColumnWidth(0, targetWidth); + + assertEquals(targetWidth, sheet.getColumnWidth(0)); + } + + @Test + void whenAutoSizeColumn_thenColumnExpands() { + + int originalWidth = sheet.getColumnWidth(0); + + sheet.autoSizeColumn(0); + + assertThat(sheet.getColumnWidth(0)).isGreaterThan(originalWidth); + } + + @AfterEach + void cleanup() throws IOException { + workbook.close(); + } + +} \ No newline at end of file diff --git a/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/mergeandremoveduplicate/MergeArraysAndRemoveDuplicate.java b/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/mergeandremoveduplicate/MergeArraysAndRemoveDuplicate.java new file mode 100644 index 0000000000..e0b249565f --- /dev/null +++ b/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/mergeandremoveduplicate/MergeArraysAndRemoveDuplicate.java @@ -0,0 +1,96 @@ +package com.baeldung.mergeandremoveduplicate; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; +import java.util.stream.Stream; + +public class MergeArraysAndRemoveDuplicate { + + public static int[] removeDuplicateOnSortedArray(int[] arr) { + // Initialize a new array to store unique elements + int[] uniqueArray = new int[arr.length]; + uniqueArray[0] = arr[0]; + int uniqueCount = 1; + + // Iterate through the sorted array to remove duplicates + for (int i = 1; i < arr.length; i++) { + if (arr[i] != arr[i - 1]) { + uniqueArray[uniqueCount] = arr[i]; + uniqueCount++; + } + } + int[] truncatedArray = new int[uniqueCount]; + System.arraycopy(uniqueArray, 0, truncatedArray, 0, uniqueCount); + return truncatedArray; + } + + public static int[] mergeAndRemoveDuplicatesUsingStream(int[] arr1, int[] arr2) { + Stream s1 = Arrays.stream(arr1).boxed(); + Stream s2 = Arrays.stream(arr2).boxed(); + return Stream.concat(s1, s2) + .distinct() + .mapToInt(Integer::intValue) + .toArray(); + } + + public static int[] mergeAndRemoveDuplicatesUsingSet(int[] arr1, int[] arr2) { + int[] mergedArr = mergeArrays(arr1, arr2); + Set uniqueInts = new HashSet<>(); + + for (int el : mergedArr) { + uniqueInts.add(el); + } + + return getArrayFromSet(uniqueInts); + } + + private static int[] getArrayFromSet(Set set) { + int[] mergedArrWithoutDuplicated = new int[set.size()]; + int i = 0; + for (Integer el: set) { + mergedArrWithoutDuplicated[i] = el; + i++; + } + return mergedArrWithoutDuplicated; + } + + public static int[] mergeAndRemoveDuplicates(int[] arr1, int[] arr2) { + return removeDuplicate(mergeArrays(arr1, arr2)); + } + + public static int[] mergeAndRemoveDuplicatesOnSortedArray(int[] arr1, int[] arr2) { + return removeDuplicateOnSortedArray(mergeArrays(arr1, arr2)); + } + + private static int[] mergeArrays(int[] arr1, int[] arr2) { + int[] mergedArrays = new int[arr1.length + arr2.length]; + System.arraycopy(arr1, 0, mergedArrays, 0, arr1.length); + System.arraycopy(arr2, 0, mergedArrays, arr1.length, arr2.length); + + return mergedArrays; + } + private static int[] removeDuplicate(int[] arr) { + int[] withoutDuplicates = new int[arr.length]; + int i = 0; + + for(int element : arr) { + if(!isElementPresent(withoutDuplicates, element)) { + withoutDuplicates[i] = element; + i++; + } + } + int[] truncatedArray = new int[i]; + System.arraycopy(withoutDuplicates, 0, truncatedArray, 0, i); + return truncatedArray; + } + + private static boolean isElementPresent(int[] arr, int element) { + for(int el : arr) { + if(el == element) { + return true; + } + } + return false; + } +} diff --git a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/mergeandremoveduplicate/MergeArraysAndRemoveDuplicateUnitTest.java b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/mergeandremoveduplicate/MergeArraysAndRemoveDuplicateUnitTest.java new file mode 100644 index 0000000000..5076ef8159 --- /dev/null +++ b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/mergeandremoveduplicate/MergeArraysAndRemoveDuplicateUnitTest.java @@ -0,0 +1,74 @@ +package com.baeldung.mergeandremoveduplicate; + +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Arrays; +import java.util.stream.Collectors; + +import static org.junit.jupiter.api.Assertions.assertArrayEquals; + +public class MergeArraysAndRemoveDuplicateUnitTest { + + private final Logger logger = LoggerFactory.getLogger(MergeArraysAndRemoveDuplicateUnitTest.class); + + private static String getCommaDelimited(int[] arr) { + return Arrays.stream(arr) + .mapToObj(Integer::toString) + .collect(Collectors.joining(", ")); + } + + @Test + public void givenNoLibraryAndUnSortedArrays_whenArr1andArr2_thenMergeAndRemoveDuplicates() { + int[] arr1 = {3, 2, 1, 4, 5, 6, 8, 7, 9}; + int[] arr2 = {8, 9, 10, 11, 12, 13, 15, 14, 15, 14, 16, 17}; + int[] expectedArr = {3, 2, 1, 4, 5, 6, 8, 7, 9, 10, 11, 12, 13, 15, 14, 16, 17}; + + int[] mergedArr = MergeArraysAndRemoveDuplicate.mergeAndRemoveDuplicates(arr1, arr2); + + //merged array maintains the order of the elements in the arrays + assertArrayEquals(expectedArr, mergedArr); + + logger.info(getCommaDelimited(mergedArr)); + } + + @Test + public void givenNoLibraryAndSortedArrays_whenArr1andArr2_thenMergeAndRemoveDuplicates() { + int[] arr1 = {1, 2, 3, 4, 5, 5, 6, 7, 7, 8}; + int[] arr2 = {8, 9, 10, 11, 12, 13, 14, 15, 15, 16, 17}; + int[] expectedArr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17}; + + int[] mergedArr = MergeArraysAndRemoveDuplicate.mergeAndRemoveDuplicatesOnSortedArray(arr1, arr2); + + assertArrayEquals(expectedArr, mergedArr); + + logger.info(getCommaDelimited(mergedArr)); + } + + @Test + public void givenSet_whenArr1andArr2_thenMergeAndRemoveDuplicates() { + int[] arr1 = {3, 2, 1, 4, 5, 6, 8, 7, 9}; + int[] arr2 = {8, 9, 10, 11, 12, 13, 15, 14, 15, 14, 16, 17}; + int[] expectedArr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17}; + + int[] mergedArr = MergeArraysAndRemoveDuplicate.mergeAndRemoveDuplicatesUsingSet(arr1, arr2); + + assertArrayEquals(expectedArr, mergedArr); + + logger.info(getCommaDelimited(mergedArr)); + } + + @Test + public void givenStream_whenArr1andArr2_thenMergeAndRemoveDuplicates() { + int[] arr1 = {3, 2, 1, 4, 5, 6, 8, 7, 9}; + int[] arr2 = {8, 9, 10, 11, 12, 13, 15, 14, 15, 14, 16, 17}; + int[] expectedArr = {3, 2, 1, 4, 5, 6, 8, 7, 9, 10, 11, 12, 13, 15, 14, 16, 17}; + + int[] mergedArr = MergeArraysAndRemoveDuplicate.mergeAndRemoveDuplicatesUsingStream(arr1, arr2); + + assertArrayEquals(expectedArr, mergedArr); + + logger.info(getCommaDelimited(mergedArr)); + } +} diff --git a/core-java-modules/core-java-arrays-operations-advanced-2/pom.xml b/core-java-modules/core-java-arrays-operations-advanced-2/pom.xml new file mode 100644 index 0000000000..53cccb8a73 --- /dev/null +++ b/core-java-modules/core-java-arrays-operations-advanced-2/pom.xml @@ -0,0 +1,46 @@ + + + 4.0.0 + core-java-arrays-operations-advanced-2 + core-java-arrays-operations-advanced-2 + jar + + + core-java-modules + com.baeldung.core-java-modules + 0.0.1-SNAPSHOT + + + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + + + + + maven-assembly-plugin + + + jar-with-dependencies + + + + + make-assembly + package + + single + + + + + + + + \ No newline at end of file diff --git a/core-java-modules/core-java-arrays-operations-advanced/src/main/java/com/baeldung/arraymiddle/MiddleOfArray.java b/core-java-modules/core-java-arrays-operations-advanced-2/src/main/java/com/baeldung/arraymiddle/MiddleOfArray.java similarity index 99% rename from core-java-modules/core-java-arrays-operations-advanced/src/main/java/com/baeldung/arraymiddle/MiddleOfArray.java rename to core-java-modules/core-java-arrays-operations-advanced-2/src/main/java/com/baeldung/arraymiddle/MiddleOfArray.java index f389893209..bfff003512 100644 --- a/core-java-modules/core-java-arrays-operations-advanced/src/main/java/com/baeldung/arraymiddle/MiddleOfArray.java +++ b/core-java-modules/core-java-arrays-operations-advanced-2/src/main/java/com/baeldung/arraymiddle/MiddleOfArray.java @@ -62,4 +62,4 @@ public class MiddleOfArray { return array[mid]; } } -} +} \ No newline at end of file diff --git a/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraymiddle/MiddleOfArrayUnitTest.java b/core-java-modules/core-java-arrays-operations-advanced-2/src/test/java/com/baeldung/arraymiddle/MiddleOfArrayUnitTest.java similarity index 99% rename from core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraymiddle/MiddleOfArrayUnitTest.java rename to core-java-modules/core-java-arrays-operations-advanced-2/src/test/java/com/baeldung/arraymiddle/MiddleOfArrayUnitTest.java index 706412d83e..64a9796e67 100644 --- a/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraymiddle/MiddleOfArrayUnitTest.java +++ b/core-java-modules/core-java-arrays-operations-advanced-2/src/test/java/com/baeldung/arraymiddle/MiddleOfArrayUnitTest.java @@ -86,4 +86,4 @@ public class MiddleOfArrayUnitTest { MiddleOfArray middleOfArray = new MiddleOfArray(); Assert.assertEquals(expectMedian, middleOfArray.medianOfArray(array, 0, 100)); } -} +} \ No newline at end of file diff --git a/core-java-modules/core-java-collections-maps-5/src/main/java/com/baeldung/map/identity/IdentityHashMapDemonstrator.java b/core-java-modules/core-java-collections-maps-5/src/main/java/com/baeldung/map/identity/IdentityHashMapDemonstrator.java index 3cbe09b93f..3b98423120 100644 --- a/core-java-modules/core-java-collections-maps-5/src/main/java/com/baeldung/map/identity/IdentityHashMapDemonstrator.java +++ b/core-java-modules/core-java-collections-maps-5/src/main/java/com/baeldung/map/identity/IdentityHashMapDemonstrator.java @@ -53,7 +53,7 @@ public class IdentityHashMapDemonstrator { } } - private static class Book { + static class Book { String title; int year; diff --git a/core-java-modules/core-java-collections-maps-5/src/test/java/com/baeldung/map/identity/IdentityHashMapDemonstratorUnitTest.java b/core-java-modules/core-java-collections-maps-5/src/test/java/com/baeldung/map/identity/IdentityHashMapDemonstratorUnitTest.java index cc74ce4dd6..388338c3ab 100644 --- a/core-java-modules/core-java-collections-maps-5/src/test/java/com/baeldung/map/identity/IdentityHashMapDemonstratorUnitTest.java +++ b/core-java-modules/core-java-collections-maps-5/src/test/java/com/baeldung/map/identity/IdentityHashMapDemonstratorUnitTest.java @@ -1,8 +1,11 @@ package com.baeldung.map.identity; +import com.baeldung.map.identity.IdentityHashMapDemonstrator.Book; import org.junit.jupiter.api.Test; import java.util.IdentityHashMap; +import org.junit.jupiter.api.condition.EnabledForJreRange; +import org.junit.jupiter.api.condition.JRE; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -18,4 +21,44 @@ public class IdentityHashMapDemonstratorUnitTest { assertEquals("Fantasy", identityHashMap.get("genre")); assertEquals("Drama", identityHashMap.get(newGenreKey)); } + + @Test + @EnabledForJreRange(max = JRE.JAVA_19) + public void removeEntryComparingValueByEquality() { + Book book = new Book("A Passage to India", 1924); + IdentityHashMap identityHashMap = new IdentityHashMap<>(10); + identityHashMap.put(book, "A great work of fiction"); + identityHashMap.remove(book, new String("A great work of fiction")); + assertEquals(null, identityHashMap.get(book)); + } + + @Test + @EnabledForJreRange(max = JRE.JAVA_19) + public void replaceEntryComparingValueByEquality() { + Book book = new Book("A Passage to India", 1924); + IdentityHashMap identityHashMap = new IdentityHashMap<>(10); + identityHashMap.put(book, "A great work of fiction"); + identityHashMap.replace(book, new String("A great work of fiction"), "One of the greatest books"); + assertEquals("One of the greatest books", identityHashMap.get(book)); + } + + @Test + @EnabledForJreRange(min = JRE.JAVA_20) + public void dontRemoveEntryComparingValueByEquality() { + Book book = new Book("A Passage to India", 1924); + IdentityHashMap identityHashMap = new IdentityHashMap<>(10); + identityHashMap.put(book, "A great work of fiction"); + identityHashMap.remove(book, new String("A great work of fiction")); + assertEquals("A great work of fiction", identityHashMap.get(book)); + } + + @Test + @EnabledForJreRange(min = JRE.JAVA_20) + public void dontReplaceEntryComparingValueByEquality() { + Book book = new Book("A Passage to India", 1924); + IdentityHashMap identityHashMap = new IdentityHashMap<>(10); + identityHashMap.put(book, "A great work of fiction"); + identityHashMap.replace(book, new String("A great work of fiction"), "One of the greatest books"); + assertEquals("A great work of fiction", identityHashMap.get(book)); + } } diff --git a/core-java-modules/core-java-io/src/test/java/com/baeldung/extension/ExtensionFromMimeTypeUnitTest.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/extension/ExtensionFromMimeTypeUnitTest.java index f8f42861cc..2238cfcafa 100644 --- a/core-java-modules/core-java-io/src/test/java/com/baeldung/extension/ExtensionFromMimeTypeUnitTest.java +++ b/core-java-modules/core-java-io/src/test/java/com/baeldung/extension/ExtensionFromMimeTypeUnitTest.java @@ -14,7 +14,7 @@ import org.apache.tika.mime.MimeTypeException; import org.junit.Test; -import com.j256.simplemagic.ContentInfo; +import com.j256.simplemagic.ContentType; public class ExtensionFromMimeTypeUnitTest { private static final String IMAGE_JPEG_MIME_TYPE = "image/jpeg"; @@ -39,8 +39,7 @@ public class ExtensionFromMimeTypeUnitTest { @Test public void whenUsingMimetypesFileTypeMap_thenGetFileExtension() { List expectedExtensions = Arrays.asList("jpeg", "jpg", "jpe"); - ContentInfo contentInfo = new ContentInfo("", IMAGE_JPEG_MIME_TYPE, "", true); - String[] detectedExtensions = contentInfo.getFileExtensions(); + String[] detectedExtensions = ContentType.fromMimeType(IMAGE_JPEG_MIME_TYPE).getFileExtensions(); assertThat(detectedExtensions).containsExactlyElementsOf(expectedExtensions); } diff --git a/core-java-modules/core-java-networking/src/test/java/com/baeldung/socket/EchoIntegrationTest.java b/core-java-modules/core-java-networking/src/test/java/com/baeldung/socket/EchoIntegrationTest.java index 103824b6aa..1e85b9d6dd 100644 --- a/core-java-modules/core-java-networking/src/test/java/com/baeldung/socket/EchoIntegrationTest.java +++ b/core-java-modules/core-java-networking/src/test/java/com/baeldung/socket/EchoIntegrationTest.java @@ -24,7 +24,7 @@ public class EchoIntegrationTest { Executors.newSingleThreadExecutor() .submit(() -> new EchoServer().start(port)); - Thread.sleep(500); + Thread.sleep(2000); } private EchoClient client = new EchoClient(); diff --git a/core-java-modules/core-java-networking/src/test/java/com/baeldung/socket/GreetServerIntegrationTest.java b/core-java-modules/core-java-networking/src/test/java/com/baeldung/socket/GreetServerIntegrationTest.java index 2bded156c5..09f20c970d 100644 --- a/core-java-modules/core-java-networking/src/test/java/com/baeldung/socket/GreetServerIntegrationTest.java +++ b/core-java-modules/core-java-networking/src/test/java/com/baeldung/socket/GreetServerIntegrationTest.java @@ -27,7 +27,7 @@ public class GreetServerIntegrationTest { Executors.newSingleThreadExecutor() .submit(() -> new GreetServer().start(port)); - Thread.sleep(500); + Thread.sleep(2000); } @Before diff --git a/core-java-modules/core-java-networking/src/test/java/com/baeldung/socket/SocketEchoMultiIntegrationTest.java b/core-java-modules/core-java-networking/src/test/java/com/baeldung/socket/SocketEchoMultiIntegrationTest.java index 62e2dd44ae..f08542c1aa 100644 --- a/core-java-modules/core-java-networking/src/test/java/com/baeldung/socket/SocketEchoMultiIntegrationTest.java +++ b/core-java-modules/core-java-networking/src/test/java/com/baeldung/socket/SocketEchoMultiIntegrationTest.java @@ -23,7 +23,7 @@ public class SocketEchoMultiIntegrationTest { s.close(); Executors.newSingleThreadExecutor().submit(() -> new EchoMultiServer().start(port)); - Thread.sleep(500); + Thread.sleep(2000); } @Test diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index 7fbd6cf657..34e5204868 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -65,6 +65,7 @@ core-java-arrays-convert core-java-arrays-operations-basic core-java-arrays-operations-advanced + core-java-arrays-operations-advanced-2 core-java-booleans core-java-char core-java-collections diff --git a/pom.xml b/pom.xml index c65f6ce62d..060f158888 100644 --- a/pom.xml +++ b/pom.xml @@ -816,6 +816,7 @@ apache-olingo apache-poi-2 + apache-poi-3 apache-thrift apache-tika @@ -1089,6 +1090,7 @@ apache-olingo apache-poi-2 + apache-poi-3 apache-thrift apache-tika diff --git a/spring-boot-modules/spring-boot-autoconfiguration/pom.xml b/spring-boot-modules/spring-boot-autoconfiguration/pom.xml index 7a3f9f01e8..7880a033f8 100644 --- a/spring-boot-modules/spring-boot-autoconfiguration/pom.xml +++ b/spring-boot-modules/spring-boot-autoconfiguration/pom.xml @@ -10,9 +10,10 @@ This is simple boot application demonstrating a custom auto-configuration - com.baeldung.spring-boot-modules - spring-boot-modules - 1.0.0-SNAPSHOT + com.baeldung + parent-boot-3 + 0.0.1-SNAPSHOT + ../../parent-boot-3 @@ -66,6 +67,13 @@ org.apache.maven.plugins maven-war-plugin + + org.springframework.boot + spring-boot-maven-plugin + + com.baeldung.autoconfiguration.example.AutoconfigurationApplication + + diff --git a/spring-boot-modules/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/MySQLAutoconfiguration.java b/spring-boot-modules/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/MySQLAutoconfiguration.java index 295e0d74c9..c470656597 100644 --- a/spring-boot-modules/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/MySQLAutoconfiguration.java +++ b/spring-boot-modules/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/MySQLAutoconfiguration.java @@ -3,10 +3,10 @@ package com.baeldung.autoconfiguration; import java.util.Arrays; import java.util.Properties; -import javax.persistence.EntityManagerFactory; import javax.sql.DataSource; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.AutoConfigureOrder; import org.springframework.boot.autoconfigure.condition.ConditionMessage; import org.springframework.boot.autoconfigure.condition.ConditionMessage.Style; @@ -20,7 +20,6 @@ import org.springframework.boot.autoconfigure.condition.SpringBootCondition; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ConditionContext; import org.springframework.context.annotation.Conditional; -import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; import org.springframework.core.Ordered; import org.springframework.core.env.Environment; @@ -31,7 +30,9 @@ import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; import org.springframework.util.ClassUtils; -@Configuration +import jakarta.persistence.EntityManagerFactory; + +@AutoConfiguration @ConditionalOnClass(DataSource.class) @AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE) @PropertySource("classpath:mysql.properties") diff --git a/spring-boot-modules/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/annotationprocessor/DatabaseProperties.java b/spring-boot-modules/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/annotationprocessor/DatabaseProperties.java index 4fb5b408a2..47f07c808f 100644 --- a/spring-boot-modules/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/annotationprocessor/DatabaseProperties.java +++ b/spring-boot-modules/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/annotationprocessor/DatabaseProperties.java @@ -1,11 +1,13 @@ package com.baeldung.autoconfiguration.annotationprocessor; -import javax.validation.constraints.Max; -import javax.validation.constraints.Min; + import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Configuration; +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; + @Configuration @ConfigurationProperties(prefix = "database") public class DatabaseProperties { diff --git a/spring-boot-modules/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/example/MyUser.java b/spring-boot-modules/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/example/MyUser.java index 31ce0fd969..26a2e04e2f 100644 --- a/spring-boot-modules/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/example/MyUser.java +++ b/spring-boot-modules/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/example/MyUser.java @@ -1,7 +1,7 @@ package com.baeldung.autoconfiguration.example; -import javax.persistence.Entity; -import javax.persistence.Id; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; @Entity public class MyUser { diff --git a/spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/META-INF/spring.factories b/spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/META-INF/spring.factories index 11c775fc6c..e69de29bb2 100644 --- a/spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/META-INF/spring.factories +++ b/spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/META-INF/spring.factories @@ -1 +0,0 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.baeldung.autoconfiguration.MySQLAutoconfiguration diff --git a/spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 0000000000..ab28361814 --- /dev/null +++ b/spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +com.baeldung.autoconfiguration.MySQLAutoconfiguration diff --git a/spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/mysql.properties b/spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/mysql.properties index 74f1ee1373..27092f852f 100644 --- a/spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/mysql.properties +++ b/spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/mysql.properties @@ -1,5 +1,5 @@ usemysql=local -mysql-hibernate.dialect=org.hibernate.dialect.MySQL5Dialect +mysql-hibernate.dialect=org.hibernate.dialect.MySQLDialect mysql-hibernate.show_sql=true mysql-hibernate.hbm2ddl.auto=create-drop \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-jasypt/pom.xml b/spring-boot-modules/spring-boot-jasypt/pom.xml index f48cd78595..70bbe35319 100644 --- a/spring-boot-modules/spring-boot-jasypt/pom.xml +++ b/spring-boot-modules/spring-boot-jasypt/pom.xml @@ -27,7 +27,7 @@ com.github.ulisesbocchio - jasypt-spring-boot-starter + jasypt-spring-boot-starter ${jasypt.version} @@ -46,15 +46,7 @@ - - - spring-milestone - Spring Milestone - https://repo.spring.io/milestone - - - - 2.0.0 + 3.0.5 \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-ssl-bundles/README.md b/spring-boot-modules/spring-boot-ssl-bundles/README.md new file mode 100644 index 0000000000..5616cce48b --- /dev/null +++ b/spring-boot-modules/spring-boot-ssl-bundles/README.md @@ -0,0 +1 @@ +## Relevant Articles diff --git a/spring-boot-modules/spring-boot-ssl-bundles/pom.xml b/spring-boot-modules/spring-boot-ssl-bundles/pom.xml new file mode 100644 index 0000000000..056d0308c2 --- /dev/null +++ b/spring-boot-modules/spring-boot-ssl-bundles/pom.xml @@ -0,0 +1,56 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.1.3 + + + springbootsslbundles + spring-boot-ssl-bundles + jar + Module for showing usage of SSL Bundles + + + org.springframework.boot + spring-boot-starter-security + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.security + spring-security-test + test + + + org.apache.httpcomponents.client5 + httpclient5-fluent + ${apache.client5.version} + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + 5.0.3 + + + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-ssl-bundles/src/main/java/com/baeldung/springbootsslbundles/SSLBundlesApp.java b/spring-boot-modules/spring-boot-ssl-bundles/src/main/java/com/baeldung/springbootsslbundles/SSLBundlesApp.java new file mode 100644 index 0000000000..f6cfb35d1e --- /dev/null +++ b/spring-boot-modules/spring-boot-ssl-bundles/src/main/java/com/baeldung/springbootsslbundles/SSLBundlesApp.java @@ -0,0 +1,19 @@ +package com.baeldung.springbootsslbundles; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.web.client.RestTemplate; +import org.springframework.boot.ssl.SslBundles; + +@SpringBootApplication +public class SSLBundlesApp { + public static void main(String[] args) { + SpringApplication.run(SSLBundlesApp.class, args); + } + @Bean + public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder, SslBundles sslBundles) { + return restTemplateBuilder.setSslBundle(sslBundles.getBundle("secure-service")).build(); + } +} diff --git a/spring-boot-modules/spring-boot-ssl-bundles/src/main/java/com/baeldung/springbootsslbundles/SecureRestTemplateConfig.java b/spring-boot-modules/spring-boot-ssl-bundles/src/main/java/com/baeldung/springbootsslbundles/SecureRestTemplateConfig.java new file mode 100644 index 0000000000..48eda219dd --- /dev/null +++ b/spring-boot-modules/spring-boot-ssl-bundles/src/main/java/com/baeldung/springbootsslbundles/SecureRestTemplateConfig.java @@ -0,0 +1,38 @@ +package com.baeldung.springbootsslbundles; + +import org.apache.hc.client5.http.classic.HttpClient; +import org.apache.hc.client5.http.impl.classic.HttpClients; +import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder; +import org.apache.hc.client5.http.io.HttpClientConnectionManager; +import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory; +import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactoryBuilder; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.ssl.NoSuchSslBundleException; +import org.springframework.boot.ssl.SslBundle; +import org.springframework.boot.ssl.SslBundles; +import org.springframework.context.annotation.Bean; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; + +import javax.net.ssl.SSLContext; + +@Component +public class SecureRestTemplateConfig { + private final SSLContext sslContext; + + @Autowired + public SecureRestTemplateConfig(SslBundles sslBundles) throws NoSuchSslBundleException { + SslBundle sslBundle = sslBundles.getBundle("secure-service"); + this.sslContext = sslBundle.createSslContext(); + } + + @Bean + public RestTemplate secureRestTemplate() { + final SSLConnectionSocketFactory sslSocketFactory = SSLConnectionSocketFactoryBuilder.create().setSslContext(this.sslContext).build(); + final HttpClientConnectionManager cm = PoolingHttpClientConnectionManagerBuilder.create().setSSLSocketFactory(sslSocketFactory).build(); + HttpClient httpClient = HttpClients.custom().setConnectionManager(cm).evictExpiredConnections().build(); + HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(httpClient); + return new RestTemplate(factory); + } +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-ssl-bundles/src/main/java/com/baeldung/springbootsslbundles/SecureServiceRestApi.java b/spring-boot-modules/spring-boot-ssl-bundles/src/main/java/com/baeldung/springbootsslbundles/SecureServiceRestApi.java new file mode 100644 index 0000000000..3ed919b957 --- /dev/null +++ b/spring-boot-modules/spring-boot-ssl-bundles/src/main/java/com/baeldung/springbootsslbundles/SecureServiceRestApi.java @@ -0,0 +1,28 @@ +package com.baeldung.springbootsslbundles; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; + +@Service +public class SecureServiceRestApi { + private final RestTemplate restTemplate; + + @Autowired + public SecureServiceRestApi(RestTemplate restTemplate) { + this.restTemplate = restTemplate; + } + + public String fetchData(String dataId) { + ResponseEntity response = restTemplate.exchange( + "https://secure-service.com/api/data/{id}", + HttpMethod.GET, + null, + String.class, + dataId + ); + return response.getBody(); + } +} diff --git a/spring-boot-modules/spring-boot-ssl-bundles/src/main/resources/application.yml b/spring-boot-modules/spring-boot-ssl-bundles/src/main/resources/application.yml new file mode 100644 index 0000000000..1598645805 --- /dev/null +++ b/spring-boot-modules/spring-boot-ssl-bundles/src/main/resources/application.yml @@ -0,0 +1,11 @@ +spring: + ssl: + bundle: + jks: + secure-service: + key: + alias: "secure-service" + keystore: + location: "classpath:keystore.p12" + password: "FooBar" + type: "PKCS12" \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-ssl-bundles/src/main/resources/cert.pem b/spring-boot-modules/spring-boot-ssl-bundles/src/main/resources/cert.pem new file mode 100644 index 0000000000..82ed122a80 --- /dev/null +++ b/spring-boot-modules/spring-boot-ssl-bundles/src/main/resources/cert.pem @@ -0,0 +1,31 @@ +-----BEGIN CERTIFICATE----- +MIIFazCCA1OgAwIBAgIUCJcVMwyhLy/ln+ENMXbSWcsO0aswDQYJKoZIhvcNAQEL +BQAwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoM +GEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDAeFw0yMzA5MDUxNjAyMzdaFw0yNDA5 +MDQxNjAyMzdaMEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEw +HwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwggIiMA0GCSqGSIb3DQEB +AQUAA4ICDwAwggIKAoICAQDMNn+ZmPfR4FUyG6PVGBB2rOAnIHqFqYMVyDUOtZja +9CxpgbQjHRwwWaUWcYzLPOsvN/tMC8BazAFHSI2KIeNKgjAesv9JTumqgFXdOmw8 +KT7a9C1IQXnCMhlbp9J7c7CLvjAvZvZBghxFLc7xBZo9rWA67QMZoOhXvdMoKv4G +5v9qD1ZqIKlCxJQrdErVUKyZPztlIWNqzPy9BJzFlBea2ArfrASulqJuWGyO09+o +6ABNgUAicp/zfCOeKIe9cni0oZj6Buwk4eVdYESzVohBO52h95KtN17Y/Tw+U8W5 +Szq9tit6Vkupbe8tih7Bkdnj22WeCLVwWdXCp1kJw2kFDJTiC3wQRa6P0OrVpPGx +Z5SmG9eSCz22alA+I521ZG85hmPDt3BleYRYlCtcW7GFT/7zLBEwlN93lY5Os1jj +PRS8o5eIg8UhTbU4QEaZRYcLzaFy0asfKfa4ZF3mH5whh/w07SEEBAKDfQPpiz3T +migd+r9qUnPWeoE8Hi7lA1KzUd4YeM2yNHqXoQiARjHkM4yrX6vVlfT+itVbrpqF +a5J7PjL26w+DsxvRt9Ad5gpOdDzuy5m2V6lphMDjeZoG4OXgBzQQ1YxK1r6wkI4U +ZwRNrb+BxmQebQHnXKEXI7jgS45uoFENwolIHm9Dou5VYGLI0z+/pDReugCcw2lO +/QIDAQABo1MwUTAdBgNVHQ4EFgQUlSkON/OM9HCXeaQ7VWQuiEwY2iAwHwYDVR0j +BBgwFoAUlSkON/OM9HCXeaQ7VWQuiEwY2iAwDwYDVR0TAQH/BAUwAwEB/zANBgkq +hkiG9w0BAQsFAAOCAgEAD+8sPSQR3+A4F9z704OOy1Mo6bvbnIuK9UdN7d4/zh+e +AoloyTFPLPZIldg9hXwCvrKjrfqS5YUKmXIp9tetX7ns13CeDFcqVwZfPnqjzdNN +ad255LEwMjIUm9hSNEV6AQBKW8E+a590SrUamEdkFm4fcUB1LaINwyJjls7C0VB2 +JL50OloaUlv0IMnAPRVp0Adlt9xs69R2B8Q4i297FvHB1PI7VMLYqNnX2+tnvszO +HvWtIqm6foyReDLfC0n87cuEBV7/9304V5vgEj20TR19isd0LffJDD1ujDXvN8dS +uGOB1VLRxAPonr9Iqk358EJ1T22uEcMdKE+sMnCBjw2fYIYRfjhGN+m6U6sb4MrF +zFUI6qB7W7T/5iukiRb4pLQ0OGgKOwYxpZoxcB3Ldjo5x58uKNOTNJ5zEJ8HUofA +BNfty10D3m3DlSyYbf7m1UUM0jj2l83LBGQzhGGUZgCnCsMczLrj64Gvf2iLGmCF +gu5zrxL01dptBkvTsYJwYBA67BBS4FcgYNMGx3m1uPsVUUIguJxufXWYfbub74QV +a1SH1NjO8HR3DLDU+S92tyTKWOUzJ5qOegEsR2cutVRzDuVTsFy7kayuNv/uLRrG +3P2HnUo8PG/nmysReBk6CGycUiDTt55DoPYGoQ5l19xTlkIt7ulNg7yX5pwFMeE= +-----END CERTIFICATE----- diff --git a/spring-boot-modules/spring-boot-ssl-bundles/src/main/resources/key.pem b/spring-boot-modules/spring-boot-ssl-bundles/src/main/resources/key.pem new file mode 100644 index 0000000000..b4202e9a8e --- /dev/null +++ b/spring-boot-modules/spring-boot-ssl-bundles/src/main/resources/key.pem @@ -0,0 +1,54 @@ +-----BEGIN ENCRYPTED PRIVATE KEY----- +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 +7NNrMLXj3PGrZ2vzKDGSAU1LzLOUrJ4m +-----END ENCRYPTED PRIVATE KEY----- diff --git a/spring-boot-modules/spring-boot-ssl-bundles/src/main/resources/keystore.p12 b/spring-boot-modules/spring-boot-ssl-bundles/src/main/resources/keystore.p12 new file mode 100644 index 0000000000..f58b355467 Binary files /dev/null and b/spring-boot-modules/spring-boot-ssl-bundles/src/main/resources/keystore.p12 differ diff --git a/spring-boot-modules/spring-boot-ssl-bundles/src/main/resources/static/index.html b/spring-boot-modules/spring-boot-ssl-bundles/src/main/resources/static/index.html new file mode 100644 index 0000000000..117910cc89 --- /dev/null +++ b/spring-boot-modules/spring-boot-ssl-bundles/src/main/resources/static/index.html @@ -0,0 +1,13 @@ + + + + + Spring SSL Bundler Demo Application + + +

Spring SSL Bundler Demo Application

+

+ This is a sample application that can be built as native executable. +

+ + diff --git a/spring-boot-modules/spring-boot-ssl-bundles/src/test/java/com/baeldung/springbootsslbundles/SSLBundleApplicationTests.java b/spring-boot-modules/spring-boot-ssl-bundles/src/test/java/com/baeldung/springbootsslbundles/SSLBundleApplicationTests.java new file mode 100644 index 0000000000..876641c8b5 --- /dev/null +++ b/spring-boot-modules/spring-boot-ssl-bundles/src/test/java/com/baeldung/springbootsslbundles/SSLBundleApplicationTests.java @@ -0,0 +1,12 @@ +package com.baeldung.springbootsslbundles; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class SSLBundleApplicationTests { + @Test + void contextLoads() { + + } +} diff --git a/spring-cloud-modules/spring-cloud-task/springcloudtaskbatch/src/main/resources/application.yml b/spring-cloud-modules/spring-cloud-task/springcloudtaskbatch/src/main/resources/application.yml index 71275793ec..b7cd3e7726 100644 --- a/spring-cloud-modules/spring-cloud-task/springcloudtaskbatch/src/main/resources/application.yml +++ b/spring-cloud-modules/spring-cloud-task/springcloudtaskbatch/src/main/resources/application.yml @@ -19,8 +19,4 @@ spring: hibernate: dialect: org.hibernate.dialect.MySQL5Dialect batch: - initialize-schema: always -maven: - remoteRepositories: - springRepo: - url: https://repo.spring.io/libs-snapshot \ No newline at end of file + initialize-schema: always \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-task/springcloudtasksink/src/main/resources/application.properties b/spring-cloud-modules/spring-cloud-task/springcloudtasksink/src/main/resources/application.properties index 1660dc8516..e69de29bb2 100644 --- a/spring-cloud-modules/spring-cloud-task/springcloudtasksink/src/main/resources/application.properties +++ b/spring-cloud-modules/spring-cloud-task/springcloudtasksink/src/main/resources/application.properties @@ -1 +0,0 @@ -maven.remoteRepositories.springRepo.url=https://repo.spring.io/libs-snapshot \ No newline at end of file diff --git a/spring-reactive-modules/pom.xml b/spring-reactive-modules/pom.xml index e75682da78..309687f011 100644 --- a/spring-reactive-modules/pom.xml +++ b/spring-reactive-modules/pom.xml @@ -27,6 +27,7 @@ spring-5-reactive-filters spring-5-reactive-oauth spring-5-reactive-security + spring-data-couchbase spring-reactive spring-reactive-exceptions spring-reactor diff --git a/spring-reactive-modules/spring-5-data-reactive/README.md b/spring-reactive-modules/spring-5-data-reactive/README.md index ecb6d01267..3522d9681b 100644 --- a/spring-reactive-modules/spring-5-data-reactive/README.md +++ b/spring-reactive-modules/spring-5-data-reactive/README.md @@ -6,5 +6,4 @@ This module contains articles about reactive Spring 5 Data The "REST With Spring" Classes: http://bit.ly/restwithspring ### Relevant Articles -- [A Quick Look at R2DBC with Spring Data](https://www.baeldung.com/spring-data-r2dbc) -- [Spring Data Reactive Repositories with Couchbase](https://www.baeldung.com/spring-data-reactive-couchbase) +- [A Quick Look at R2DBC with Spring Data](https://www.baeldung.com/spring-data-r2dbc) \ No newline at end of file diff --git a/spring-reactive-modules/spring-5-data-reactive/pom.xml b/spring-reactive-modules/spring-5-data-reactive/pom.xml index e4d3aeeddd..dc4a5b9bd1 100644 --- a/spring-reactive-modules/spring-5-data-reactive/pom.xml +++ b/spring-reactive-modules/spring-5-data-reactive/pom.xml @@ -26,15 +26,6 @@ - - io.projectreactor - reactor-core - ${reactor-core.version} - - - org.springframework.boot - spring-boot-starter-data-couchbase-reactive - org.springframework.boot spring-boot-starter-web @@ -42,21 +33,12 @@ org.projectlombok lombok - ${lombok.version} io.projectreactor reactor-test test - - io.reactivex.rxjava2 - rxjava - - - org.springframework - spring-test - org.springframework.boot spring-boot-starter-test @@ -66,101 +48,27 @@ org.springframework.boot spring-boot-starter-webflux - - org.springframework - spring-tx - ${spring-tx.version} - org.springframework.data spring-data-r2dbc - ${spring-data-r2dbc.version} io.r2dbc r2dbc-h2 - ${r2dbc-h2.version} - - - com.h2database - h2 - - - org.apache.httpcomponents - httpclient - ${httpclient.version} - - - com.couchbase.mock - CouchbaseMock - ${couchbaseMock.version} - test - - org.apache.maven.plugins - maven-surefire-plugin - - - --add-opens java.base/java.util=ALL-UNNAMED - - - org.springframework.boot spring-boot-maven-plugin - - org.apache.maven.plugins - maven-compiler-plugin - - ${java.version} - ${java.version} - - - - - default-compile - none - - - - default-testCompile - none - - - java-compile - compile - - compile - - - - java-test-compile - test-compile - - testCompile - - - - - 5.2.2.RELEASE - 1.0.0.RELEASE - 0.8.1.RELEASE - 4.5.2 - 1.5.23 - 3.3.1.RELEASE - - 2.2.6.RELEASE 2.17.1 - 1.18.26 \ No newline at end of file diff --git a/spring-reactive-modules/spring-5-data-reactive/src/test/java/com/baeldung/r2dbc/R2dbcApplicationIntegrationTest.java b/spring-reactive-modules/spring-5-data-reactive/src/test/java/com/baeldung/r2dbc/R2dbcApplicationIntegrationTest.java index 1af570587e..b5e859ae2f 100644 --- a/spring-reactive-modules/spring-5-data-reactive/src/test/java/com/baeldung/r2dbc/R2dbcApplicationIntegrationTest.java +++ b/spring-reactive-modules/spring-5-data-reactive/src/test/java/com/baeldung/r2dbc/R2dbcApplicationIntegrationTest.java @@ -1,6 +1,7 @@ package com.baeldung.r2dbc; +import com.baeldung.r2dbc.configuration.R2DBCConfiguration; import com.baeldung.r2dbc.model.Player; import com.baeldung.r2dbc.repository.PlayerRepository; import io.r2dbc.h2.H2ConnectionFactory; @@ -9,7 +10,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.data.r2dbc.core.DatabaseClient; +import org.springframework.r2dbc.core.DatabaseClient; import org.springframework.test.context.junit4.SpringRunner; import reactor.core.publisher.Flux; import reactor.core.publisher.Hooks; @@ -20,7 +21,7 @@ import java.util.Arrays; import java.util.List; @RunWith(SpringRunner.class) -@SpringBootTest +@SpringBootTest(classes = R2DBCConfiguration.class) public class R2dbcApplicationIntegrationTest { @@ -43,7 +44,7 @@ public class R2dbcApplicationIntegrationTest { "DROP TABLE IF EXISTS player;", "CREATE table player (id INT AUTO_INCREMENT NOT NULL, name VARCHAR2, age INT NOT NULL);"); - statements.forEach(it -> client.execute(it) // + statements.forEach(it -> client.sql(it) // .fetch() // .rowsUpdated() // .as(StepVerifier::create) // diff --git a/spring-reactive-modules/spring-data-couchbase/README.md b/spring-reactive-modules/spring-data-couchbase/README.md new file mode 100644 index 0000000000..e38ef10562 --- /dev/null +++ b/spring-reactive-modules/spring-data-couchbase/README.md @@ -0,0 +1,9 @@ +## Spring Data Reactive Project + +This module contains articles about reactive Spring Data Couchbase + +### The Course +The "REST With Spring" Classes: http://bit.ly/restwithspring + +### Relevant Articles +- [Spring Data Reactive Repositories with Couchbase](https://www.baeldung.com/spring-data-reactive-couchbase) diff --git a/spring-reactive-modules/spring-data-couchbase/pom.xml b/spring-reactive-modules/spring-data-couchbase/pom.xml new file mode 100644 index 0000000000..68ddd1cefa --- /dev/null +++ b/spring-reactive-modules/spring-data-couchbase/pom.xml @@ -0,0 +1,146 @@ + + + 4.0.0 + spring-data-couchbase + spring-data-couchbase + jar + + + com.baeldung.spring.reactive + spring-reactive-modules + 1.0.0-SNAPSHOT + + + + + + org.apache.logging.log4j + log4j-bom + ${log4j2.version} + import + pom + + + + + + + io.projectreactor + reactor-core + ${reactor-core.version} + + + org.springframework.boot + spring-boot-starter-data-couchbase-reactive + + + org.springframework.boot + spring-boot-starter-web + + + org.projectlombok + lombok + ${lombok.version} + + + io.projectreactor + reactor-test + test + + + io.reactivex.rxjava2 + rxjava + + + org.springframework + spring-test + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework + spring-tx + ${spring-tx.version} + + + org.apache.httpcomponents + httpclient + ${httpclient.version} + + + com.couchbase.mock + CouchbaseMock + ${couchbaseMock.version} + test + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + --add-opens java.base/java.util=ALL-UNNAMED + + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-compiler-plugin + + ${java.version} + ${java.version} + + + + + default-compile + none + + + + default-testCompile + none + + + java-compile + compile + + compile + + + + java-test-compile + test-compile + + testCompile + + + + + + + + + 5.2.2.RELEASE + 4.5.2 + 1.5.23 + 3.3.1.RELEASE + + 2.2.6.RELEASE + 2.17.1 + 1.18.26 + + + \ No newline at end of file diff --git a/spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/couchbase/ReactiveCouchbaseApplication.java b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/ReactiveCouchbaseApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/couchbase/ReactiveCouchbaseApplication.java rename to spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/ReactiveCouchbaseApplication.java diff --git a/spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/couchbase/configuration/CouchbaseProperties.java b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/CouchbaseProperties.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/couchbase/configuration/CouchbaseProperties.java rename to spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/CouchbaseProperties.java diff --git a/spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/couchbase/configuration/N1QLReactiveCouchbaseConfiguration.java b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/N1QLReactiveCouchbaseConfiguration.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/couchbase/configuration/N1QLReactiveCouchbaseConfiguration.java rename to spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/N1QLReactiveCouchbaseConfiguration.java diff --git a/spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/couchbase/configuration/ReactiveCouchbaseConfiguration.java b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/ReactiveCouchbaseConfiguration.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/couchbase/configuration/ReactiveCouchbaseConfiguration.java rename to spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/ReactiveCouchbaseConfiguration.java diff --git a/spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/couchbase/configuration/ViewReactiveCouchbaseConfiguration.java b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/ViewReactiveCouchbaseConfiguration.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/couchbase/configuration/ViewReactiveCouchbaseConfiguration.java rename to spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/ViewReactiveCouchbaseConfiguration.java diff --git a/spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/couchbase/domain/Person.java b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/Person.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/couchbase/domain/Person.java rename to spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/Person.java diff --git a/spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLPersonRepository.java b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLPersonRepository.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLPersonRepository.java rename to spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLPersonRepository.java diff --git a/spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLSortingPersonRepository.java b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLSortingPersonRepository.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLSortingPersonRepository.java rename to spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLSortingPersonRepository.java diff --git a/spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/couchbase/domain/repository/view/ViewPersonRepository.java b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/repository/view/ViewPersonRepository.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/couchbase/domain/repository/view/ViewPersonRepository.java rename to spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/repository/view/ViewPersonRepository.java diff --git a/spring-reactive-modules/spring-5-data-reactive/src/main/resources/couchbase.properties b/spring-reactive-modules/spring-data-couchbase/src/main/resources/couchbase.properties similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/main/resources/couchbase.properties rename to spring-reactive-modules/spring-data-couchbase/src/main/resources/couchbase.properties diff --git a/spring-reactive-modules/spring-data-couchbase/src/main/resources/logback.xml b/spring-reactive-modules/spring-data-couchbase/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/spring-reactive-modules/spring-data-couchbase/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/spring-reactive-modules/spring-5-data-reactive/src/test/java/com/baeldung/couchbase/domain/repository/CouchbaseMockConfiguration.java b/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/CouchbaseMockConfiguration.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/test/java/com/baeldung/couchbase/domain/repository/CouchbaseMockConfiguration.java rename to spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/CouchbaseMockConfiguration.java diff --git a/spring-reactive-modules/spring-5-data-reactive/src/test/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLPersonRepositoryLiveTest.java b/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLPersonRepositoryLiveTest.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/test/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLPersonRepositoryLiveTest.java rename to spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLPersonRepositoryLiveTest.java diff --git a/spring-reactive-modules/spring-5-data-reactive/src/test/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLSortingPersonRepositoryLiveTest.java b/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLSortingPersonRepositoryLiveTest.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/test/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLSortingPersonRepositoryLiveTest.java rename to spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLSortingPersonRepositoryLiveTest.java diff --git a/spring-reactive-modules/spring-5-data-reactive/src/test/java/com/baeldung/couchbase/domain/repository/view/ViewPersonRepositoryIntegrationTest.java b/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/view/ViewPersonRepositoryIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/test/java/com/baeldung/couchbase/domain/repository/view/ViewPersonRepositoryIntegrationTest.java rename to spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/view/ViewPersonRepositoryIntegrationTest.java