org.springframework
@@ -208,6 +215,9 @@
1.5.1
+
+
+ 2.5
\ No newline at end of file
diff --git a/spring-static-resources/src/main/java/com/baeldung/loadresourceasstring/LoadResourceConfig.java b/spring-static-resources/src/main/java/com/baeldung/loadresourceasstring/LoadResourceConfig.java
new file mode 100644
index 0000000000..32b9ba84d0
--- /dev/null
+++ b/spring-static-resources/src/main/java/com/baeldung/loadresourceasstring/LoadResourceConfig.java
@@ -0,0 +1,15 @@
+package com.baeldung.loadresourceasstring;
+
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class LoadResourceConfig {
+
+ @Bean
+ public String resourceString() {
+ return ResourceReader.readFileToString("resource.txt");
+ }
+
+}
diff --git a/spring-static-resources/src/main/java/com/baeldung/loadresourceasstring/ResourceReader.java b/spring-static-resources/src/main/java/com/baeldung/loadresourceasstring/ResourceReader.java
new file mode 100644
index 0000000000..7bc1babe91
--- /dev/null
+++ b/spring-static-resources/src/main/java/com/baeldung/loadresourceasstring/ResourceReader.java
@@ -0,0 +1,30 @@
+package com.baeldung.loadresourceasstring;
+
+import org.springframework.core.io.DefaultResourceLoader;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.ResourceLoader;
+import org.springframework.util.FileCopyUtils;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.UncheckedIOException;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+
+
+public class ResourceReader {
+
+ public static String readFileToString(String path) {
+ ResourceLoader resourceLoader = new DefaultResourceLoader();
+ Resource resource = resourceLoader.getResource(path);
+ return asString(resource);
+ }
+
+ public static String asString(Resource resource) {
+ try (Reader reader = new InputStreamReader(resource.getInputStream(), UTF_8)) {
+ return FileCopyUtils.copyToString(reader);
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
+ }
+}
diff --git a/spring-static-resources/src/main/resources/resource.txt b/spring-static-resources/src/main/resources/resource.txt
new file mode 100644
index 0000000000..e78cfa90c2
--- /dev/null
+++ b/spring-static-resources/src/main/resources/resource.txt
@@ -0,0 +1 @@
+This is a resource text file. This file will be loaded as a resource and use its contents as a string.
\ No newline at end of file
diff --git a/spring-static-resources/src/test/java/com/baeldung/loadresourceasstring/LoadResourceAsStringIntegrationTest.java b/spring-static-resources/src/test/java/com/baeldung/loadresourceasstring/LoadResourceAsStringIntegrationTest.java
new file mode 100644
index 0000000000..c16c1a9720
--- /dev/null
+++ b/spring-static-resources/src/test/java/com/baeldung/loadresourceasstring/LoadResourceAsStringIntegrationTest.java
@@ -0,0 +1,57 @@
+package com.baeldung.loadresourceasstring;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.core.convert.converter.Converter;
+import org.springframework.core.io.DefaultResourceLoader;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.ResourceLoader;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.support.AnnotationConfigContextLoader;
+import org.springframework.util.FileCopyUtils;
+
+import java.io.InputStreamReader;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.junit.Assert.assertEquals;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(loader = AnnotationConfigContextLoader.class, classes = LoadResourceConfig.class)
+public class LoadResourceAsStringIntegrationTest {
+
+ private static final String EXPECTED_RESOURCE_VALUE = "This is a resource text file. This file will be loaded as a " + "resource and use its contents as a string.";
+
+ @Value("#{T(com.baeldung.loadresourceasstring.ResourceReader).readFileToString('classpath:resource.txt')}")
+ private String resourceStringUsingSpel;
+
+ @Autowired
+ @Qualifier("resourceString")
+ private String resourceString;
+
+ @Autowired
+ private ResourceLoader resourceLoader;
+
+ @Test
+ public void givenUsingResourceLoadAndFileCopyUtils_whenConvertingAResourceToAString_thenCorrect() {
+ Resource resource = resourceLoader.getResource("classpath:resource.txt");
+ assertEquals(EXPECTED_RESOURCE_VALUE, ResourceReader.asString(resource));
+ }
+
+ @Test
+ public void givenUsingResourceStringBean_whenConvertingAResourceToAString_thenCorrect() {
+ assertEquals(EXPECTED_RESOURCE_VALUE, resourceString);
+ }
+
+ @Test
+ public void givenUsingSpel_whenConvertingAResourceToAString_thenCorrect() {
+ assertEquals(EXPECTED_RESOURCE_VALUE, resourceStringUsingSpel);
+ }
+
+
+
+
+}
diff --git a/spring-thymeleaf-2/pom.xml b/spring-thymeleaf-2/pom.xml
new file mode 100644
index 0000000000..bc1147cb14
--- /dev/null
+++ b/spring-thymeleaf-2/pom.xml
@@ -0,0 +1,40 @@
+
+ 4.0.0
+ spring-thymeleaf-2
+ spring-thymeleaf-2
+ 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-thymeleaf
+
+
+
+
+ 1.8
+ 1.8
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-war-plugin
+
+
+ spring-thymeleaf-2
+
+
diff --git a/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/Application.java b/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/Application.java
new file mode 100644
index 0000000000..2ccca82497
--- /dev/null
+++ b/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/Application.java
@@ -0,0 +1,11 @@
+package com.baeldung.thymeleaf;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class Application {
+ public static void main(String[] args) {
+ SpringApplication.run(Application.class, args);
+ }
+}
diff --git a/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/enums/Color.java b/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/enums/Color.java
new file mode 100644
index 0000000000..9e223d1323
--- /dev/null
+++ b/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/enums/Color.java
@@ -0,0 +1,22 @@
+package com.baeldung.thymeleaf.enums;
+
+public enum Color {
+ BLACK("Black"),
+ BLUE("Blue"),
+ RED("Red"),
+ YELLOW("Yellow"),
+ GREEN("Green"),
+ ORANGE("Orange"),
+ PURPLE("Purple"),
+ WHITE("White");
+
+ private final String displayValue;
+
+ private Color(String displayValue) {
+ this.displayValue = displayValue;
+ }
+
+ public String getDisplayValue() {
+ return displayValue;
+ }
+}
diff --git a/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/enums/Widget.java b/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/enums/Widget.java
new file mode 100644
index 0000000000..dc6504c3bc
--- /dev/null
+++ b/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/enums/Widget.java
@@ -0,0 +1,27 @@
+package com.baeldung.thymeleaf.enums;
+
+public class Widget {
+ private String name;
+ private Color color;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Color getColor() {
+ return color;
+ }
+
+ public void setColor(Color color) {
+ this.color = color;
+ }
+
+ @Override
+ public String toString() {
+ return "Widget [name=" + name + ", color=" + color + "]";
+ }
+}
diff --git a/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/enums/WidgetController.java b/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/enums/WidgetController.java
new file mode 100644
index 0000000000..c66464d75b
--- /dev/null
+++ b/spring-thymeleaf-2/src/main/java/com/baeldung/thymeleaf/enums/WidgetController.java
@@ -0,0 +1,23 @@
+package com.baeldung.thymeleaf.enums;
+
+import javax.validation.Valid;
+
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.ModelAttribute;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.ui.Model;
+
+@Controller
+public class WidgetController {
+ @GetMapping("/widget/add")
+ public String addWidget(@ModelAttribute Widget widget) {
+ return "enums/new";
+ }
+
+ @PostMapping("/widget/add")
+ public String saveWidget(@Valid Widget widget, Model model) {
+ model.addAttribute("widget", widget);
+ return "enums/view";
+ }
+}
diff --git a/spring-thymeleaf-2/src/main/resources/templates/enums/new.html b/spring-thymeleaf-2/src/main/resources/templates/enums/new.html
new file mode 100644
index 0000000000..7ac4665171
--- /dev/null
+++ b/spring-thymeleaf-2/src/main/resources/templates/enums/new.html
@@ -0,0 +1,19 @@
+
+
+
+
+Enums in Thymeleaf
+
+
+
+
+
\ No newline at end of file
diff --git a/spring-thymeleaf-2/src/main/resources/templates/enums/view.html b/spring-thymeleaf-2/src/main/resources/templates/enums/view.html
new file mode 100644
index 0000000000..f766f66277
--- /dev/null
+++ b/spring-thymeleaf-2/src/main/resources/templates/enums/view.html
@@ -0,0 +1,30 @@
+
+
+
+
+Enums in Thymeleaf
+
+
+ View Widget
+
+ Name:
+
+
+
+ Color:
+
+
+
+ This color screams danger.
+
+
+ Green is for go.
+
+
+ Alert
+ Warning
+ Caution
+ All Good
+
+
+
\ No newline at end of file
diff --git a/testing-modules/junit-5-advanced/src/test/java/com/baeldung/displayname/ReplaceUnderscoresGeneratorUnitTest.java b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/displayname/ReplaceUnderscoresGeneratorUnitTest.java
new file mode 100644
index 0000000000..429d6bac2a
--- /dev/null
+++ b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/displayname/ReplaceUnderscoresGeneratorUnitTest.java
@@ -0,0 +1,20 @@
+package com.baeldung.displayname;
+
+import org.junit.jupiter.api.*;
+
+@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class)
+class ReplaceUnderscoresGeneratorUnitTest {
+
+ @Nested
+ class when_doing_something {
+
+ @Test
+ void then_something_should_happen() {
+ }
+
+ @Test
+ @DisplayName("@DisplayName takes precedence over generation")
+ void override_generator() {
+ }
+ }
+}
diff --git a/testing-modules/spring-testing/README.md b/testing-modules/spring-testing/README.md
index 8eb282643a..07888d7cdf 100644
--- a/testing-modules/spring-testing/README.md
+++ b/testing-modules/spring-testing/README.md
@@ -4,3 +4,4 @@
- [A Quick Guide to @TestPropertySource](https://www.baeldung.com/spring-test-property-source)
- [Guide to ReflectionTestUtils for Unit Testing](https://www.baeldung.com/spring-reflection-test-utils)
- [How to Test the @Scheduled Annotation](https://www.baeldung.com/spring-testing-scheduled-annotation)
+- [Override properties in Spring]()
\ No newline at end of file
diff --git a/testing-modules/spring-testing/pom.xml b/testing-modules/spring-testing/pom.xml
index 10d34f169b..0eca9b6a7e 100644
--- a/testing-modules/spring-testing/pom.xml
+++ b/testing-modules/spring-testing/pom.xml
@@ -26,7 +26,6 @@
org.springframework.boot
spring-boot-starter
LATEST
- test