org.jetbrains.kotlin
@@ -175,8 +180,8 @@
2.9.0
2.9.9
1.2.71
- com.baeldung.Spring5Application
4.5.8
+ com.baeldung.Spring5Application
diff --git a/spring-5-mvc/src/main/resources/application.properties b/spring-5-mvc/src/main/resources/application.properties
index 886ea1978b..ccec014c2b 100644
--- a/spring-5-mvc/src/main/resources/application.properties
+++ b/spring-5-mvc/src/main/resources/application.properties
@@ -1,6 +1,3 @@
server.port=8081
-security.user.name=user
-security.user.password=pass
-
logging.level.root=INFO
\ No newline at end of file
diff --git a/spring-core-3/src/main/java/com/baeldung/ioccontainer/bean/CustomBeanFactoryPostProcessor.java b/spring-core-3/src/main/java/com/baeldung/ioccontainer/bean/CustomBeanFactoryPostProcessor.java
new file mode 100644
index 0000000000..65e249b15b
--- /dev/null
+++ b/spring-core-3/src/main/java/com/baeldung/ioccontainer/bean/CustomBeanFactoryPostProcessor.java
@@ -0,0 +1,21 @@
+package com.baeldung.ioccontainer.bean;
+
+import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+
+public class CustomBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
+ private static boolean isBeanFactoryPostProcessorRegistered = false;
+
+ @Override
+ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory){
+ setBeanFactoryPostProcessorRegistered(true);
+ }
+
+ public static boolean isBeanFactoryPostProcessorRegistered() {
+ return isBeanFactoryPostProcessorRegistered;
+ }
+
+ public static void setBeanFactoryPostProcessorRegistered(boolean isBeanFactoryPostProcessorRegistered) {
+ CustomBeanFactoryPostProcessor.isBeanFactoryPostProcessorRegistered = isBeanFactoryPostProcessorRegistered;
+ }
+}
diff --git a/spring-core-3/src/main/java/com/baeldung/ioccontainer/bean/CustomBeanPostProcessor.java b/spring-core-3/src/main/java/com/baeldung/ioccontainer/bean/CustomBeanPostProcessor.java
new file mode 100644
index 0000000000..6f99a5f0db
--- /dev/null
+++ b/spring-core-3/src/main/java/com/baeldung/ioccontainer/bean/CustomBeanPostProcessor.java
@@ -0,0 +1,21 @@
+package com.baeldung.ioccontainer.bean;
+
+import org.springframework.beans.factory.config.BeanPostProcessor;
+
+public class CustomBeanPostProcessor implements BeanPostProcessor {
+ private static boolean isBeanPostProcessorRegistered = false;
+
+ @Override
+ public Object postProcessBeforeInitialization(Object bean, String beanName){
+ setBeanPostProcessorRegistered(true);
+ return bean;
+ }
+
+ public static boolean isBeanPostProcessorRegistered() {
+ return isBeanPostProcessorRegistered;
+ }
+
+ public static void setBeanPostProcessorRegistered(boolean isBeanPostProcessorRegistered) {
+ CustomBeanPostProcessor.isBeanPostProcessorRegistered = isBeanPostProcessorRegistered;
+ }
+}
diff --git a/spring-core-3/src/main/java/com/baeldung/ioccontainer/bean/Student.java b/spring-core-3/src/main/java/com/baeldung/ioccontainer/bean/Student.java
new file mode 100644
index 0000000000..404f323b66
--- /dev/null
+++ b/spring-core-3/src/main/java/com/baeldung/ioccontainer/bean/Student.java
@@ -0,0 +1,17 @@
+package com.baeldung.ioccontainer.bean;
+
+public class Student {
+ private static boolean isBeanInstantiated = false;
+
+ public void postConstruct() {
+ setBeanInstantiated(true);
+ }
+
+ public static boolean isBeanInstantiated() {
+ return isBeanInstantiated;
+ }
+
+ public static void setBeanInstantiated(boolean isBeanInstantiated) {
+ Student.isBeanInstantiated = isBeanInstantiated;
+ }
+}
diff --git a/spring-core-3/src/test/java/com/baeldung/ioccontainer/IOCContainerAppUnitTest.java b/spring-core-3/src/test/java/com/baeldung/ioccontainer/IOCContainerAppUnitTest.java
new file mode 100644
index 0000000000..e9b491813e
--- /dev/null
+++ b/spring-core-3/src/test/java/com/baeldung/ioccontainer/IOCContainerAppUnitTest.java
@@ -0,0 +1,86 @@
+package com.baeldung.ioccontainer;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+import org.springframework.beans.factory.xml.XmlBeanFactory;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
+
+import com.baeldung.ioccontainer.bean.CustomBeanFactoryPostProcessor;
+import com.baeldung.ioccontainer.bean.CustomBeanPostProcessor;
+import com.baeldung.ioccontainer.bean.Student;
+
+public class IOCContainerAppUnitTest {
+
+ @BeforeEach
+ @AfterEach
+ public void resetInstantiationFlag() {
+ Student.setBeanInstantiated(false);
+ CustomBeanPostProcessor.setBeanPostProcessorRegistered(false);
+ CustomBeanFactoryPostProcessor.setBeanFactoryPostProcessorRegistered(false);
+ }
+
+ @Test
+ public void whenBFInitialized_thenStudentNotInitialized() {
+ Resource res = new ClassPathResource("ioc-container-difference-example.xml");
+ BeanFactory factory = new XmlBeanFactory(res);
+
+ assertFalse(Student.isBeanInstantiated());
+ }
+
+ @Test
+ public void whenBFInitialized_thenStudentInitialized() {
+ Resource res = new ClassPathResource("ioc-container-difference-example.xml");
+ BeanFactory factory = new XmlBeanFactory(res);
+ Student student = (Student) factory.getBean("student");
+
+ assertTrue(Student.isBeanInstantiated());
+ }
+
+ @Test
+ public void whenAppContInitialized_thenStudentInitialized() {
+ ApplicationContext context = new ClassPathXmlApplicationContext("ioc-container-difference-example.xml");
+
+ assertTrue(Student.isBeanInstantiated());
+ }
+
+ @Test
+ public void whenBFInitialized_thenBFPProcessorAndBPProcessorNotRegAutomatically() {
+ Resource res = new ClassPathResource("ioc-container-difference-example.xml");
+ ConfigurableListableBeanFactory factory = new XmlBeanFactory(res);
+
+ assertFalse(CustomBeanFactoryPostProcessor.isBeanFactoryPostProcessorRegistered());
+ assertFalse(CustomBeanPostProcessor.isBeanPostProcessorRegistered());
+ }
+
+ @Test
+ public void whenBFPostProcessorAndBPProcessorRegisteredManually_thenReturnTrue() {
+ Resource res = new ClassPathResource("ioc-container-difference-example.xml");
+ ConfigurableListableBeanFactory factory = new XmlBeanFactory(res);
+
+ CustomBeanFactoryPostProcessor beanFactoryPostProcessor = new CustomBeanFactoryPostProcessor();
+ beanFactoryPostProcessor.postProcessBeanFactory(factory);
+ assertTrue(CustomBeanFactoryPostProcessor.isBeanFactoryPostProcessorRegistered());
+
+ CustomBeanPostProcessor beanPostProcessor = new CustomBeanPostProcessor();
+ factory.addBeanPostProcessor(beanPostProcessor);
+ Student student = (Student) factory.getBean("student");
+ assertTrue(CustomBeanPostProcessor.isBeanPostProcessorRegistered());
+ }
+
+ @Test
+ public void whenAppContInitialized_thenBFPostProcessorAndBPostProcessorRegisteredAutomatically() {
+ ApplicationContext context = new ClassPathXmlApplicationContext("ioc-container-difference-example.xml");
+
+ assertTrue(CustomBeanFactoryPostProcessor.isBeanFactoryPostProcessorRegistered());
+ assertTrue(CustomBeanPostProcessor.isBeanPostProcessorRegistered());
+ }
+}
diff --git a/spring-core-3/src/test/resources/ioc-container-difference-example.xml b/spring-core-3/src/test/resources/ioc-container-difference-example.xml
new file mode 100644
index 0000000000..e53dc11f89
--- /dev/null
+++ b/spring-core-3/src/test/resources/ioc-container-difference-example.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/spring-thymeleaf-3/README.md b/spring-thymeleaf-3/README.md
new file mode 100644
index 0000000000..e1ddd727d7
--- /dev/null
+++ b/spring-thymeleaf-3/README.md
@@ -0,0 +1,5 @@
+## Spring Thymeleaf 3
+
+This module contains articles about Spring with Thymeleaf
+
+## Relevant Articles:
\ No newline at end of file
diff --git a/spring-thymeleaf-3/pom.xml b/spring-thymeleaf-3/pom.xml
new file mode 100644
index 0000000000..7677e50d79
--- /dev/null
+++ b/spring-thymeleaf-3/pom.xml
@@ -0,0 +1,78 @@
+
+
+ 4.0.0
+ spring-thymeleaf-3
+ spring-thymeleaf-3
+ 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
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+ com.baeldung.thymeleaf.cssandjs.CssAndJsApplication
+ JAR
+
+
+
+ org.apache.maven.plugins
+ maven-war-plugin
+
+
+
+ org.apache.tomcat.maven
+ tomcat7-maven-plugin
+ ${tomcat7-maven-plugin.version}
+
+
+ tomcat-run
+
+ exec-war-only
+
+ package
+
+ /
+ false
+ webapp.jar
+ utf-8
+
+
+
+
+
+ spring-thymeleaf-3
+
+
+
+ 1.8
+ 1.8
+ 2.2
+
+
+
diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/Application.java b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/Application.java
new file mode 100644
index 0000000000..2ccca82497
--- /dev/null
+++ b/spring-thymeleaf-3/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-3/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsApplication.java b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsApplication.java
new file mode 100644
index 0000000000..fc6c142b8b
--- /dev/null
+++ b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsApplication.java
@@ -0,0 +1,11 @@
+package com.baeldung.thymeleaf.cssandjs;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class CssAndJsApplication {
+ public static void main(String[] args) {
+ SpringApplication.run(CssAndJsApplication.class, args);
+ }
+}
diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsController.java b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsController.java
new file mode 100644
index 0000000000..b56a7b468e
--- /dev/null
+++ b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsController.java
@@ -0,0 +1,15 @@
+package com.baeldung.thymeleaf.cssandjs;
+
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.GetMapping;
+
+@Controller
+public class CssAndJsController {
+
+ @GetMapping("/styled-page")
+ public String getStyledPage(Model model) {
+ model.addAttribute("name", "Baeldung Reader");
+ return "cssandjs/styledPage";
+ }
+}
diff --git a/spring-thymeleaf-3/src/main/resources/static/js/cssandjs/actions.js b/spring-thymeleaf-3/src/main/resources/static/js/cssandjs/actions.js
new file mode 100644
index 0000000000..e192e6358e
--- /dev/null
+++ b/spring-thymeleaf-3/src/main/resources/static/js/cssandjs/actions.js
@@ -0,0 +1,7 @@
+function showAlert() {
+ alert("The button was clicked!");
+}
+
+function showName(name) {
+ alert("Here's the name: " + name);
+}
\ No newline at end of file
diff --git a/spring-thymeleaf-3/src/main/resources/static/styles/cssandjs/main.css b/spring-thymeleaf-3/src/main/resources/static/styles/cssandjs/main.css
new file mode 100644
index 0000000000..1f57b4616a
--- /dev/null
+++ b/spring-thymeleaf-3/src/main/resources/static/styles/cssandjs/main.css
@@ -0,0 +1,18 @@
+h2 {
+ font-family: sans-serif;
+ font-size: 1.5em;
+ text-transform: uppercase;
+}
+
+strong {
+ font-weight: 700;
+ background-color: yellow;
+}
+
+p {
+ font-family: sans-serif;
+}
+
+label {
+ font-weight: 600;
+}
\ No newline at end of file
diff --git a/spring-thymeleaf-3/src/main/resources/templates/cssandjs/styledPage.html b/spring-thymeleaf-3/src/main/resources/templates/cssandjs/styledPage.html
new file mode 100644
index 0000000000..12e4fc9227
--- /dev/null
+++ b/spring-thymeleaf-3/src/main/resources/templates/cssandjs/styledPage.html
@@ -0,0 +1,20 @@
+
+
+
+
+ Add CSS and JS to Thymeleaf
+
+
+
+
+
+ Carefully Styled Heading
+
+ This is text on which we want to apply very special styling.
+
+
+
+
+
\ No newline at end of file
diff --git a/spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/ApplicationIntegrationTest.java b/spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/ApplicationIntegrationTest.java
new file mode 100644
index 0000000000..b7cfa140f0
--- /dev/null
+++ b/spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/ApplicationIntegrationTest.java
@@ -0,0 +1,13 @@
+package com.baeldung.thymeleaf;
+
+import org.junit.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+
+@SpringBootTest
+public class ApplicationIntegrationTest {
+
+ @Test
+ public void contextLoads() {
+
+ }
+}
diff --git a/spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/cssandjs/CssAndJsControllerIntegrationTest.java b/spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/cssandjs/CssAndJsControllerIntegrationTest.java
new file mode 100644
index 0000000000..365608bd2a
--- /dev/null
+++ b/spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/cssandjs/CssAndJsControllerIntegrationTest.java
@@ -0,0 +1,41 @@
+package com.baeldung.thymeleaf.cssandjs;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
+import org.springframework.test.web.servlet.setup.MockMvcBuilders;
+import org.springframework.web.context.WebApplicationContext;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@WebAppConfiguration
+@ContextConfiguration(classes = CssAndJsApplication.class)
+public class CssAndJsControllerIntegrationTest {
+ @Autowired
+ private WebApplicationContext context;
+
+ private MockMvc mockMvc;
+
+ @Before
+ public void setup() {
+ this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context).build();
+ }
+
+ @Test
+ public void whenCalledGetStyledPage_thenReturnContent() throws Exception {
+ this.mockMvc.perform(MockMvcRequestBuilders.get("/styled-page"))
+ .andExpect(status().isOk())
+ .andExpect(view().name("cssandjs/styledPage"))
+ .andExpect(content().string(containsString("Carefully Styled Heading")));
+ }
+}