diff --git a/spring-5-reactive/README.md b/spring-5-reactive/README.md
index 7c078a8f92..9998dbf751 100644
--- a/spring-5-reactive/README.md
+++ b/spring-5-reactive/README.md
@@ -16,3 +16,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [Reactive WebSockets with Spring 5](http://www.baeldung.com/spring-5-reactive-websockets)
- [Spring Boot Actuator](http://www.baeldung.com/spring-boot-actuators)
- [Spring Webflux Filters](http://www.baeldung.com/spring-webflux-filters)
+- [Reactive Flow with MongoDB, Kotlin, and Spring WebFlux](http://www.baeldung.com/kotlin-mongodb-spring-webflux)
diff --git a/spring-5/README.md b/spring-5/README.md
index d37927cfc7..de42d965f5 100644
--- a/spring-5/README.md
+++ b/spring-5/README.md
@@ -16,3 +16,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [Introduction to Spring REST Docs](http://www.baeldung.com/spring-rest-docs)
- [Spring Security 5 – OAuth2 Login](http://www.baeldung.com/spring-security-5-oauth2-login)
- [Spring ResponseStatusException](http://www.baeldung.com/spring-response-status-exception)
+- [Spring Assert Statements](http://www.baeldung.com/spring-assert)
diff --git a/spring-all/README.md b/spring-all/README.md
index 0902a11a77..a3e1ca5464 100644
--- a/spring-all/README.md
+++ b/spring-all/README.md
@@ -12,7 +12,7 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [Properties with Spring](http://www.baeldung.com/properties-with-spring) - checkout the `org.baeldung.properties` package for all scenarios of properties injection and usage
- [Spring Profiles](http://www.baeldung.com/spring-profiles)
- [A Spring Custom Annotation for a Better DAO](http://www.baeldung.com/spring-annotation-bean-pre-processor)
-- [What's New in Spring 4.3?](http://www.baeldung.com/whats-new-in-spring-4-3/)
+- [What's New in Spring 4.3?](http://www.baeldung.com/whats-new-in-spring-4-3)
- [Guide To Running Logic on Startup in Spring](http://www.baeldung.com/running-setup-logic-on-startup-in-spring)
- [Quick Guide to Spring Controllers](http://www.baeldung.com/spring-controllers)
- [Quick Guide to Spring Bean Scopes](http://www.baeldung.com/spring-bean-scopes)
@@ -26,3 +26,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [Model, ModelMap, and ModelView in Spring MVC](http://www.baeldung.com/spring-mvc-model-model-map-model-view)
- [A Guide To Caching in Spring](http://www.baeldung.com/spring-cache-tutorial)
- [How To Do @Async in Spring](http://www.baeldung.com/spring-async)
+- [Quick Guide to the Spring @Order Annotation](http://www.baeldung.com/spring-order)
diff --git a/spring-all/pom.xml b/spring-all/pom.xml
index ac66ecdad8..f9ced963e7 100644
--- a/spring-all/pom.xml
+++ b/spring-all/pom.xml
@@ -170,6 +170,7 @@
org.springframework.boot
spring-boot-starter-thymeleaf
+ ${org.springframework.version}
diff --git a/spring-all/src/main/java/com/baeldung/contexts/config/AnnotationsBasedApplicationAndServletInitializer.java b/spring-all/src/main/java/com/baeldung/contexts/config/AnnotationsBasedApplicationAndServletInitializer.java
new file mode 100644
index 0000000000..4df1e2e73b
--- /dev/null
+++ b/spring-all/src/main/java/com/baeldung/contexts/config/AnnotationsBasedApplicationAndServletInitializer.java
@@ -0,0 +1,36 @@
+package com.baeldung.contexts.config;
+
+import org.springframework.web.context.WebApplicationContext;
+import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
+import org.springframework.web.servlet.support.AbstractDispatcherServletInitializer;
+
+public class AnnotationsBasedApplicationAndServletInitializer extends AbstractDispatcherServletInitializer {
+
+ @Override
+ protected WebApplicationContext createRootApplicationContext() {
+ //If this is not the only class declaring a root context, we return null because it would clash
+ //with other classes, as there can only be a single root context.
+
+ //AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
+ //rootContext.register(RootApplicationConfig.class);
+ //return rootContext;
+ return null;
+ }
+
+ @Override
+ protected WebApplicationContext createServletApplicationContext() {
+ AnnotationConfigWebApplicationContext normalWebAppContext = new AnnotationConfigWebApplicationContext();
+ normalWebAppContext.register(NormalWebAppConfig.class);
+ return normalWebAppContext;
+ }
+
+ @Override
+ protected String[] getServletMappings() {
+ return new String[] { "/api/*" };
+ }
+
+ @Override
+ protected String getServletName() {
+ return "normal-dispatcher";
+ }
+}
diff --git a/spring-all/src/main/java/com/baeldung/contexts/config/AnnotationsBasedApplicationInitializer.java b/spring-all/src/main/java/com/baeldung/contexts/config/AnnotationsBasedApplicationInitializer.java
new file mode 100644
index 0000000000..0d2674d4f3
--- /dev/null
+++ b/spring-all/src/main/java/com/baeldung/contexts/config/AnnotationsBasedApplicationInitializer.java
@@ -0,0 +1,16 @@
+package com.baeldung.contexts.config;
+
+import org.springframework.web.context.AbstractContextLoaderInitializer;
+import org.springframework.web.context.WebApplicationContext;
+import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
+
+public class AnnotationsBasedApplicationInitializer extends AbstractContextLoaderInitializer {
+
+ @Override
+ protected WebApplicationContext createRootApplicationContext() {
+ AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
+ rootContext.register(RootApplicationConfig.class);
+ return rootContext;
+ }
+
+}
\ No newline at end of file
diff --git a/spring-all/src/main/java/com/baeldung/contexts/config/ApplicationInitializer.java b/spring-all/src/main/java/com/baeldung/contexts/config/ApplicationInitializer.java
index c3ff90cf39..09e0742394 100644
--- a/spring-all/src/main/java/com/baeldung/contexts/config/ApplicationInitializer.java
+++ b/spring-all/src/main/java/com/baeldung/contexts/config/ApplicationInitializer.java
@@ -5,31 +5,36 @@ import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import org.springframework.context.annotation.Configuration;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
+import org.springframework.web.context.support.XmlWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
-@Configuration
public class ApplicationInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
- AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
- rootContext.register(RootApplicationConfig.class);
- servletContext.addListener(new ContextLoaderListener(rootContext));
-
- AnnotationConfigWebApplicationContext normalWebAppContext = new AnnotationConfigWebApplicationContext();
- normalWebAppContext.register(NormalWebAppConfig.class);
- ServletRegistration.Dynamic normal = servletContext.addServlet("normal-webapp", new DispatcherServlet(normalWebAppContext));
- normal.setLoadOnStartup(1);
- normal.addMapping("/api/*");
-
- AnnotationConfigWebApplicationContext secureWebAppContext = new AnnotationConfigWebApplicationContext();
- secureWebAppContext.register(SecureWebAppConfig.class);
- ServletRegistration.Dynamic secure = servletContext.addServlet("secure-webapp", new DispatcherServlet(secureWebAppContext));
- secure.setLoadOnStartup(1);
- secure.addMapping("/s/api/*");
+ //Here, we can define a root context and register servlets, among other things.
+ //However, since we've later defined other classes to do the same and they would clash,
+ //we leave this commented out.
+
+ //Root XML Context
+ //XmlWebApplicationContext rootContext = new XmlWebApplicationContext();
+ //rootContext.setConfigLocations("/WEB-INF/rootApplicationContext.xml");
+ //Annotations Context
+ //AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
+ //rootContext.register(RootApplicationConfig.class);
+ //Registration
+ //servletContext.addListener(new ContextLoaderListener(rootContext));
+
+ //Dispatcher Servlet
+ //XmlWebApplicationContext normalWebAppContext = new XmlWebApplicationContext();
+ //normalWebAppContext.setConfigLocation("/WEB-INF/normal-webapp-servlet.xml");
+ //ServletRegistration.Dynamic normal = servletContext.addServlet("normal-webapp", new DispatcherServlet(normalWebAppContext));
+ //normal.setLoadOnStartup(1);
+ //normal.addMapping("/api/*");
}
}
diff --git a/spring-all/src/main/java/com/baeldung/contexts/config/SecureAnnotationsBasedApplicationAndServletInitializer.java b/spring-all/src/main/java/com/baeldung/contexts/config/SecureAnnotationsBasedApplicationAndServletInitializer.java
new file mode 100644
index 0000000000..89ce0153f5
--- /dev/null
+++ b/spring-all/src/main/java/com/baeldung/contexts/config/SecureAnnotationsBasedApplicationAndServletInitializer.java
@@ -0,0 +1,32 @@
+package com.baeldung.contexts.config;
+
+import org.springframework.web.context.WebApplicationContext;
+import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
+import org.springframework.web.servlet.support.AbstractDispatcherServletInitializer;
+
+public class SecureAnnotationsBasedApplicationAndServletInitializer extends AbstractDispatcherServletInitializer {
+
+ @Override
+ protected WebApplicationContext createRootApplicationContext() {
+ return null;
+ }
+
+ @Override
+ protected WebApplicationContext createServletApplicationContext() {
+ AnnotationConfigWebApplicationContext secureWebAppContext = new AnnotationConfigWebApplicationContext();
+ secureWebAppContext.register(SecureWebAppConfig.class);
+ return secureWebAppContext;
+ }
+
+ @Override
+ protected String[] getServletMappings() {
+ return new String[] { "/s/api/*" };
+ }
+
+
+ @Override
+ protected String getServletName() {
+ return "secure-dispatcher";
+ }
+
+}
diff --git a/spring-all/src/main/java/com/baeldung/contexts/normal/HelloWorldController.java b/spring-all/src/main/java/com/baeldung/contexts/normal/HelloWorldController.java
index dd70ce8e97..fbe3dfb398 100644
--- a/spring-all/src/main/java/com/baeldung/contexts/normal/HelloWorldController.java
+++ b/spring-all/src/main/java/com/baeldung/contexts/normal/HelloWorldController.java
@@ -35,7 +35,7 @@ public class HelloWorldController {
@RequestMapping(path = "/welcome")
public ModelAndView helloWorld() {
processContext();
- String message = "
" + "
" + greeterService.greet() + "
";
+ String message = "
" + "
Normal " + greeterService.greet() + "
";
return new ModelAndView("welcome", "message", message);
}
}
diff --git a/spring-all/src/main/java/com/baeldung/contexts/secure/HelloWorldSecureController.java b/spring-all/src/main/java/com/baeldung/contexts/secure/HelloWorldSecureController.java
index b46ace91ae..4ebf2d55e0 100644
--- a/spring-all/src/main/java/com/baeldung/contexts/secure/HelloWorldSecureController.java
+++ b/spring-all/src/main/java/com/baeldung/contexts/secure/HelloWorldSecureController.java
@@ -43,7 +43,7 @@ public class HelloWorldSecureController {
@RequestMapping(path = "/welcome")
public ModelAndView helloWorld() {
processContext();
- String message = "
" + "
" + greeterService.greet() + "
";
+ String message = "
" + "
Secure " + greeterService.greet() + "
";
return new ModelAndView("welcome", "message", message);
}
}
diff --git a/spring-all/src/main/java/org/baeldung/caching/config/ApplicationCacheConfig.java b/spring-all/src/main/java/org/baeldung/caching/config/ApplicationCacheConfig.java
new file mode 100644
index 0000000000..8bf23de2cc
--- /dev/null
+++ b/spring-all/src/main/java/org/baeldung/caching/config/ApplicationCacheConfig.java
@@ -0,0 +1,30 @@
+package org.baeldung.caching.config;
+
+import org.springframework.cache.Cache;
+import org.springframework.cache.CacheManager;
+import org.springframework.cache.annotation.EnableCaching;
+import org.springframework.cache.concurrent.ConcurrentMapCache;
+import org.springframework.cache.interceptor.KeyGenerator;
+import org.springframework.cache.support.SimpleCacheManager;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import java.util.Arrays;
+
+@EnableCaching
+@Configuration
+public class ApplicationCacheConfig {
+
+ @Bean
+ public CacheManager cacheManager() {
+ SimpleCacheManager cacheManager = new SimpleCacheManager();
+ Cache booksCache = new ConcurrentMapCache("books");
+ cacheManager.setCaches(Arrays.asList(booksCache));
+ return cacheManager;
+ }
+
+ @Bean("customKeyGenerator")
+ public KeyGenerator keyGenerator() {
+ return new CustomKeyGenerator();
+ }
+}
diff --git a/spring-all/src/main/java/org/baeldung/caching/config/CustomKeyGenerator.java b/spring-all/src/main/java/org/baeldung/caching/config/CustomKeyGenerator.java
new file mode 100644
index 0000000000..c1da9493e0
--- /dev/null
+++ b/spring-all/src/main/java/org/baeldung/caching/config/CustomKeyGenerator.java
@@ -0,0 +1,14 @@
+package org.baeldung.caching.config;
+
+import org.springframework.cache.interceptor.KeyGenerator;
+import org.springframework.util.StringUtils;
+
+import java.lang.reflect.Method;
+
+public class CustomKeyGenerator implements KeyGenerator {
+
+ public Object generate(Object target, Method method, Object... params) {
+ return target.getClass().getSimpleName() + "_" + method.getName() + "_"
+ + StringUtils.arrayToDelimitedString(params, "_");
+ }
+}
diff --git a/spring-all/src/main/java/org/baeldung/caching/example/BookService.java b/spring-all/src/main/java/org/baeldung/caching/example/BookService.java
new file mode 100644
index 0000000000..26118d61de
--- /dev/null
+++ b/spring-all/src/main/java/org/baeldung/caching/example/BookService.java
@@ -0,0 +1,21 @@
+package org.baeldung.caching.example;
+
+import org.baeldung.model.Book;
+import org.springframework.cache.annotation.Cacheable;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Component
+public class BookService {
+
+ @Cacheable(value="books", keyGenerator="customKeyGenerator")
+ public List getBooks() {
+ List books = new ArrayList();
+ books.add(new Book(1, "The Counterfeiters", "André Gide"));
+ books.add(new Book(2, "Peer Gynt and Hedda Gabler", "Henrik Ibsen"));
+ return books;
+ }
+
+}
diff --git a/spring-all/src/main/java/org/baeldung/controller/config/StudentControllerConfig.java b/spring-all/src/main/java/org/baeldung/controller/config/StudentControllerConfig.java
index ec6cf19785..3dc4db53c0 100644
--- a/spring-all/src/main/java/org/baeldung/controller/config/StudentControllerConfig.java
+++ b/spring-all/src/main/java/org/baeldung/controller/config/StudentControllerConfig.java
@@ -19,10 +19,13 @@ public class StudentControllerConfig implements WebApplicationInitializer {
root.setServletContext(sc);
- // Manages the lifecycle of the root application context
- sc.addListener(new ContextLoaderListener(root));
+ //Manages the lifecycle of the root application context.
+ //Conflicts with other root contexts in the application, so we've manually set the parent below.
+ //sc.addListener(new ContextLoaderListener(root));
- DispatcherServlet dv = new DispatcherServlet(new GenericWebApplicationContext());
+ GenericWebApplicationContext webApplicationContext = new GenericWebApplicationContext();
+ webApplicationContext.setParent(root);
+ DispatcherServlet dv = new DispatcherServlet(webApplicationContext);
ServletRegistration.Dynamic appServlet = sc.addServlet("test-mvc", dv);
appServlet.setLoadOnStartup(1);
diff --git a/spring-all/src/main/java/org/baeldung/model/Book.java b/spring-all/src/main/java/org/baeldung/model/Book.java
new file mode 100644
index 0000000000..9305ce9653
--- /dev/null
+++ b/spring-all/src/main/java/org/baeldung/model/Book.java
@@ -0,0 +1,41 @@
+package org.baeldung.model;
+
+public class Book {
+
+ private int id;
+ private String author;
+ private String title;
+
+ public Book() {
+ }
+
+ public Book(int id, String author, String title) {
+ this.id = id;
+ this.author = author;
+ this.title = title;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getAuthor() {
+ return author;
+ }
+
+ public void setAuthor(String author) {
+ this.author = author;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+}
diff --git a/spring-all/src/main/java/org/baeldung/order/Average.java b/spring-all/src/main/java/org/baeldung/order/Average.java
new file mode 100644
index 0000000000..d1d9117fb1
--- /dev/null
+++ b/spring-all/src/main/java/org/baeldung/order/Average.java
@@ -0,0 +1,15 @@
+package org.baeldung.order;
+
+import org.springframework.core.Ordered;
+import org.springframework.core.annotation.Order;
+import org.springframework.stereotype.Component;
+
+@Component
+@Order(Ordered.LOWEST_PRECEDENCE)
+public class Average implements Rating {
+
+ @Override
+ public int getRating() {
+ return 3;
+ }
+}
diff --git a/spring-all/src/main/java/org/baeldung/order/Excellent.java b/spring-all/src/main/java/org/baeldung/order/Excellent.java
new file mode 100644
index 0000000000..e5f125593f
--- /dev/null
+++ b/spring-all/src/main/java/org/baeldung/order/Excellent.java
@@ -0,0 +1,14 @@
+package org.baeldung.order;
+
+import org.springframework.stereotype.Component;
+import org.springframework.core.annotation.Order;
+
+@Component
+@Order(1)
+public class Excellent implements Rating {
+
+ @Override
+ public int getRating() {
+ return 1;
+ }
+}
diff --git a/spring-all/src/main/java/org/baeldung/order/Good.java b/spring-all/src/main/java/org/baeldung/order/Good.java
new file mode 100644
index 0000000000..3dd9852cc4
--- /dev/null
+++ b/spring-all/src/main/java/org/baeldung/order/Good.java
@@ -0,0 +1,14 @@
+package org.baeldung.order;
+
+import org.springframework.core.annotation.Order;
+import org.springframework.stereotype.Component;
+
+@Component
+@Order(2)
+public class Good implements Rating {
+
+ @Override
+ public int getRating() {
+ return 2;
+ }
+}
diff --git a/spring-all/src/main/java/org/baeldung/order/Rating.java b/spring-all/src/main/java/org/baeldung/order/Rating.java
new file mode 100644
index 0000000000..dd0391a3d9
--- /dev/null
+++ b/spring-all/src/main/java/org/baeldung/order/Rating.java
@@ -0,0 +1,6 @@
+package org.baeldung.order;
+
+public interface Rating {
+
+ int getRating();
+}
diff --git a/spring-all/src/main/java/org/baeldung/spring/config/MainWebAppInitializer.java b/spring-all/src/main/java/org/baeldung/spring/config/MainWebAppInitializer.java
index 5ef83b8afd..a857783c60 100644
--- a/spring-all/src/main/java/org/baeldung/spring/config/MainWebAppInitializer.java
+++ b/spring-all/src/main/java/org/baeldung/spring/config/MainWebAppInitializer.java
@@ -26,11 +26,14 @@ public class MainWebAppInitializer implements WebApplicationInitializer {
root.scan("org.baeldung.spring.config");
// root.getEnvironment().setDefaultProfiles("embedded");
- // Manages the lifecycle of the root application context
- sc.addListener(new ContextLoaderListener(root));
+ //Manages the lifecycle of the root application context.
+ //Conflicts with other root contexts in the application, so we've manually set the parent below.
+ //sc.addListener(new ContextLoaderListener(root));
// Handles requests into the application
- final ServletRegistration.Dynamic appServlet = sc.addServlet("mvc", new DispatcherServlet(new GenericWebApplicationContext()));
+ GenericWebApplicationContext webApplicationContext = new GenericWebApplicationContext();
+ webApplicationContext.setParent(root);
+ final ServletRegistration.Dynamic appServlet = sc.addServlet("mvc", new DispatcherServlet(webApplicationContext));
appServlet.setLoadOnStartup(1);
final Set mappingConflicts = appServlet.addMapping("/");
if (!mappingConflicts.isEmpty()) {
diff --git a/spring-all/src/main/webapp/WEB-INF/greeting.xml b/spring-all/src/main/webapp/WEB-INF/greeting.xml
new file mode 100644
index 0000000000..3f0ae83455
--- /dev/null
+++ b/spring-all/src/main/webapp/WEB-INF/greeting.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/spring-all/src/main/webapp/WEB-INF/mvc-servlet.xml b/spring-all/src/main/webapp/WEB-INF/mvc-servlet.xml
deleted file mode 100644
index 4ba9642448..0000000000
--- a/spring-all/src/main/webapp/WEB-INF/mvc-servlet.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/spring-all/src/main/webapp/WEB-INF/normal-webapp-servlet.xml b/spring-all/src/main/webapp/WEB-INF/normal-webapp-servlet.xml
index d358e2d62b..0a7a0919a8 100644
--- a/spring-all/src/main/webapp/WEB-INF/normal-webapp-servlet.xml
+++ b/spring-all/src/main/webapp/WEB-INF/normal-webapp-servlet.xml
@@ -1,12 +1,9 @@
diff --git a/spring-all/src/main/webapp/WEB-INF/rootApplicationContext.xml b/spring-all/src/main/webapp/WEB-INF/rootApplicationContext.xml
index cd79c64e79..af03661ebc 100644
--- a/spring-all/src/main/webapp/WEB-INF/rootApplicationContext.xml
+++ b/spring-all/src/main/webapp/WEB-INF/rootApplicationContext.xml
@@ -10,7 +10,5 @@
-
-
-
+
\ No newline at end of file
diff --git a/spring-all/src/main/webapp/WEB-INF/secure-webapp-servlet.xml b/spring-all/src/main/webapp/WEB-INF/secure-webapp-servlet.xml
index 5bca724670..6cdd3971bf 100644
--- a/spring-all/src/main/webapp/WEB-INF/secure-webapp-servlet.xml
+++ b/spring-all/src/main/webapp/WEB-INF/secure-webapp-servlet.xml
@@ -1,12 +1,9 @@
diff --git a/spring-all/src/main/webapp/WEB-INF/web.xml b/spring-all/src/main/webapp/WEB-INF/web.xml
index 2050f28f81..42020e75c4 100644
--- a/spring-all/src/main/webapp/WEB-INF/web.xml
+++ b/spring-all/src/main/webapp/WEB-INF/web.xml
@@ -3,37 +3,54 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
-
-
-
+
+
+
+
+
+
+
+
+
+
-
+
-
+
+
- test-mvc
+ normal-webapp-annotations
org.springframework.web.servlet.DispatcherServlet
+
+ contextClass
+ org.springframework.web.context.support.AnnotationConfigWebApplicationContext
+
contextConfigLocation
- /WEB-INF/test-mvc.xml
+ com.baeldung.contexts.config.NormalWebAppConfig
1
-
- test-mvc
- /test/*
+ normal-webapp-annotations
+ /api-ann/*
diff --git a/spring-all/src/main/webapp/WEB-INF/web_old.xml b/spring-all/src/main/webapp/WEB-INF/web_old.xml
deleted file mode 100644
index 016369ad27..0000000000
--- a/spring-all/src/main/webapp/WEB-INF/web_old.xml
+++ /dev/null
@@ -1,41 +0,0 @@
-
-
-
- Spring MVC Application
-
-
-
- contextClass
-
- org.springframework.web.context.support.AnnotationConfigWebApplicationContext
-
-
-
- contextConfigLocation
- org.baeldung.spring.web.config
-
-
-
- org.springframework.web.context.ContextLoaderListener
-
-
-
-
- mvc
- org.springframework.web.servlet.DispatcherServlet
- 1
-
-
- mvc
- /
-
-
-
- index.html
-
-
-
\ No newline at end of file
diff --git a/spring-all/src/test/java/org/baeldung/order/RatingRetrieverUnitTest.java b/spring-all/src/test/java/org/baeldung/order/RatingRetrieverUnitTest.java
new file mode 100644
index 0000000000..a624f757fc
--- /dev/null
+++ b/spring-all/src/test/java/org/baeldung/order/RatingRetrieverUnitTest.java
@@ -0,0 +1,37 @@
+package org.baeldung.order;
+
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.support.AnnotationConfigContextLoader;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(loader = AnnotationConfigContextLoader.class)
+public class RatingRetrieverUnitTest {
+
+ @Configuration
+ @ComponentScan(basePackages = {"org.baeldung.order"})
+ static class ContextConfiguration {}
+
+ @Autowired
+ private List ratings;
+
+ @Test
+ public void givenOrderOnComponents_whenInjected_thenAutowireByOrderValue() {
+ assertThat(ratings.get(0).getRating(), is(equalTo(1)));
+ assertThat(ratings.get(1).getRating(), is(equalTo(2)));
+ assertThat(ratings.get(2).getRating(), is(equalTo(3)));
+ }
+
+}
diff --git a/spring-boot-admin/README.md b/spring-boot-admin/README.md
index 622533a6ad..73ce857059 100644
--- a/spring-boot-admin/README.md
+++ b/spring-boot-admin/README.md
@@ -14,4 +14,9 @@ and the mail configuration from application.properties
* mvn clean install
* mvn spring-boot:run
* starts on port 8081
-* basic auth client/client
\ No newline at end of file
+* basic auth client/client
+
+
+### Relevant Articles:
+
+- [A Guide to Spring Boot Admin](http://www.baeldung.com/spring-boot-admin)
diff --git a/spring-boot-autoconfiguration/.gitignore b/spring-boot-autoconfiguration/.gitignore
new file mode 100644
index 0000000000..da7c2c5c0a
--- /dev/null
+++ b/spring-boot-autoconfiguration/.gitignore
@@ -0,0 +1,5 @@
+/target/
+.settings/
+.classpath
+.project
+
diff --git a/spring-boot-autoconfiguration/README.MD b/spring-boot-autoconfiguration/README.MD
new file mode 100644
index 0000000000..a71af54dff
--- /dev/null
+++ b/spring-boot-autoconfiguration/README.MD
@@ -0,0 +1,6 @@
+### The Course
+The "REST With Spring" Classes: http://bit.ly/restwithspring
+
+### Relevant Articles:
+
+- [Create a Custom Auto-Configuration with Spring Boot](http://www.baeldung.com/spring-boot-custom-auto-configuration)
\ No newline at end of file
diff --git a/spring-boot-autoconfiguration/pom.xml b/spring-boot-autoconfiguration/pom.xml
new file mode 100644
index 0000000000..2687fcd969
--- /dev/null
+++ b/spring-boot-autoconfiguration/pom.xml
@@ -0,0 +1,108 @@
+
+ 4.0.0
+ com.baeldung
+ spring-boot-autoconfiguration
+ 0.0.1-SNAPSHOT
+ war
+ spring-boot-auto-configuration
+ This is simple boot application demonstrating a custom auto-configuration
+
+
+ parent-boot-2
+ com.baeldung
+ 0.0.1-SNAPSHOT
+ ../parent-boot-2
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-thymeleaf
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ org.springframework.boot
+ spring-boot-starter-data-jpa
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+
+ mysql
+ mysql-connector-java
+ 8.0.11
+
+
+
+
+ spring-boot
+
+
+ src/main/resources
+ true
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-war-plugin
+
+
+
+
+
+
+
+
+ autoconfiguration
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+
+ integration-test
+
+ test
+
+
+
+ **/*LiveTest.java
+ **/*IntegrationTest.java
+
+
+ **/AutoconfigurationTest.java
+
+
+
+
+
+
+ json
+
+
+
+
+
+
+
+
+
+
+ 3.1.1
+ 3.3.7-1
+ 3.1.7
+ 8.5.11
+
+
+
\ No newline at end of file
diff --git a/spring-boot/src/main/java/com/baeldung/autoconfiguration/MySQLAutoconfiguration.java b/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/MySQLAutoconfiguration.java
similarity index 100%
rename from spring-boot/src/main/java/com/baeldung/autoconfiguration/MySQLAutoconfiguration.java
rename to spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/MySQLAutoconfiguration.java
diff --git a/spring-boot/src/main/java/com/baeldung/autoconfiguration/example/AutoconfigurationApplication.java b/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/example/AutoconfigurationApplication.java
similarity index 73%
rename from spring-boot/src/main/java/com/baeldung/autoconfiguration/example/AutoconfigurationApplication.java
rename to spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/example/AutoconfigurationApplication.java
index f419dbf4fd..0c9d7060dd 100644
--- a/spring-boot/src/main/java/com/baeldung/autoconfiguration/example/AutoconfigurationApplication.java
+++ b/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/example/AutoconfigurationApplication.java
@@ -1,15 +1,12 @@
package com.baeldung.autoconfiguration.example;
-import javax.annotation.security.RolesAllowed;
-
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class AutoconfigurationApplication {
- @RolesAllowed("*")
+
public static void main(String[] args) {
- System.setProperty("security.basic.enabled", "false");
SpringApplication.run(AutoconfigurationApplication.class, args);
}
}
diff --git a/spring-boot/src/main/java/com/baeldung/autoconfiguration/example/MyUser.java b/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/example/MyUser.java
similarity index 100%
rename from spring-boot/src/main/java/com/baeldung/autoconfiguration/example/MyUser.java
rename to spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/example/MyUser.java
diff --git a/spring-boot/src/main/java/com/baeldung/autoconfiguration/example/MyUserRepository.java b/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/example/MyUserRepository.java
similarity index 100%
rename from spring-boot/src/main/java/com/baeldung/autoconfiguration/example/MyUserRepository.java
rename to spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/example/MyUserRepository.java
diff --git a/spring-boot/src/main/resources/META-INF/spring.factories b/spring-boot-autoconfiguration/src/main/resources/META-INF/spring.factories
similarity index 100%
rename from spring-boot/src/main/resources/META-INF/spring.factories
rename to spring-boot-autoconfiguration/src/main/resources/META-INF/spring.factories
diff --git a/spring-boot-autoconfiguration/src/main/resources/application.properties b/spring-boot-autoconfiguration/src/main/resources/application.properties
new file mode 100644
index 0000000000..4456c78e5d
--- /dev/null
+++ b/spring-boot-autoconfiguration/src/main/resources/application.properties
@@ -0,0 +1,2 @@
+spring.jpa.show-sql=true
+spring.jpa.hibernate.ddl-auto = update
diff --git a/spring-boot/src/main/resources/mysql.properties b/spring-boot-autoconfiguration/src/main/resources/mysql.properties
similarity index 58%
rename from spring-boot/src/main/resources/mysql.properties
rename to spring-boot-autoconfiguration/src/main/resources/mysql.properties
index 27092f852f..74f1ee1373 100644
--- a/spring-boot/src/main/resources/mysql.properties
+++ b/spring-boot-autoconfiguration/src/main/resources/mysql.properties
@@ -1,5 +1,5 @@
usemysql=local
-mysql-hibernate.dialect=org.hibernate.dialect.MySQLDialect
+mysql-hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
mysql-hibernate.show_sql=true
mysql-hibernate.hbm2ddl.auto=create-drop
\ No newline at end of file
diff --git a/spring-boot/src/test/java/com/baeldung/autoconfiguration/AutoconfigurationIntegrationTest.java b/spring-boot-autoconfiguration/src/test/java/com/baeldung/autoconfiguration/AutoconfigurationIntegrationTest.java
similarity index 100%
rename from spring-boot/src/test/java/com/baeldung/autoconfiguration/AutoconfigurationIntegrationTest.java
rename to spring-boot-autoconfiguration/src/test/java/com/baeldung/autoconfiguration/AutoconfigurationIntegrationTest.java
diff --git a/spring-boot-cli/README.md b/spring-boot-cli/README.md
index 4185415b39..85323da9b4 100644
--- a/spring-boot-cli/README.md
+++ b/spring-boot-cli/README.md
@@ -3,4 +3,4 @@
## Spring Boot CLI
### Relevant Articles:
-- [Introduction to Spring Boot CLI](http://www.baeldung.com/)
+- [Introduction to Spring Boot CLI](http://www.baeldung.com/spring-boot-cli)
diff --git a/spring-boot/.factorypath b/spring-boot/.factorypath
index 60dbd696eb..88c3910e93 100644
--- a/spring-boot/.factorypath
+++ b/spring-boot/.factorypath
@@ -1,51 +1,50 @@
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
-
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
+
@@ -53,53 +52,59 @@
-
+
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
@@ -108,47 +113,56 @@
-
-
-
-
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
-
+
+
+
+
+
-
-
-
+
+
+
-
+
-
-
-
-
-
-
+
+
+
+
+
+
diff --git a/spring-boot/README.MD b/spring-boot/README.MD
index 7e68e30a47..72da255b95 100644
--- a/spring-boot/README.MD
+++ b/spring-boot/README.MD
@@ -20,7 +20,6 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [Dynamic DTO Validation Config Retrieved from DB](http://www.baeldung.com/spring-dynamic-dto-validation)
- [Custom Information in Spring Boot Info Endpoint](http://www.baeldung.com/spring-boot-info-actuator-custom)
- [Using @JsonComponent in Spring Boot](http://www.baeldung.com/spring-boot-jsoncomponent)
-- [Create a Custom Auto-Configuration with Spring Boot](http://www.baeldung.com/spring-boot-custom-auto-configuration)
- [Testing in Spring Boot](http://www.baeldung.com/spring-boot-testing)
- [Guide to @ConfigurationProperties in Spring Boot](http://www.baeldung.com/configuration-properties-in-spring-boot)
- [How to Get All Spring-Managed Beans?](http://www.baeldung.com/spring-show-all-beans)
diff --git a/spring-boot/pom.xml b/spring-boot/pom.xml
index 127ac455e1..afc80eb68b 100644
--- a/spring-boot/pom.xml
+++ b/spring-boot/pom.xml
@@ -9,10 +9,10 @@
This is simple boot application for Spring boot actuator test
- parent-boot-5
+ parent-boot-2
com.baeldung
0.0.1-SNAPSHOT
- ../parent-boot-5
+ ../parent-boot-2
@@ -33,11 +33,6 @@
spring-boot-starter-actuator
-
- org.springframework.boot
- spring-boot-starter-security
-
-
com.graphql-java
graphql-spring-boot-starter
@@ -78,7 +73,6 @@
com.h2database
h2
- ${h2.version}
@@ -125,22 +119,14 @@
provided
-
- mysql
- mysql-connector-java
- ${mysql-connector-java.version}
-
-
org.springframework
spring-websocket
- ${spring.version}
org.springframework
spring-messaging
- ${spring.version}
@@ -186,7 +172,6 @@
pl.project13.maven
git-commit-id-plugin
- ${git-commit-id-plugin.version}
@@ -233,16 +218,12 @@
org.baeldung.demo.DemoApplication
- 4.3.4.RELEASE
- 2.2.1
3.1.1
3.3.7-1
3.1.7
8.5.11
- 1.4.194
2.4.1.Final
1.9.0
- 6.0.6
\ No newline at end of file
diff --git a/spring-boot/src/main/java/com/baeldung/annotation/servletcomponentscan/SpringBootAnnotatedApp.java b/spring-boot/src/main/java/com/baeldung/annotation/servletcomponentscan/SpringBootAnnotatedApp.java
index 774eb69889..b4d416dd96 100644
--- a/spring-boot/src/main/java/com/baeldung/annotation/servletcomponentscan/SpringBootAnnotatedApp.java
+++ b/spring-boot/src/main/java/com/baeldung/annotation/servletcomponentscan/SpringBootAnnotatedApp.java
@@ -4,8 +4,6 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
-import com.baeldung.autoconfiguration.MySQLAutoconfiguration;
-
/**
* using the following annotations are equivalent:
* -
@@ -16,7 +14,7 @@ import com.baeldung.autoconfiguration.MySQLAutoconfiguration;
*
@ServletComponentScan(basePackageClasses = {AttrListener.class, HelloFilter.class, HelloServlet.class, EchoServlet.class})
*
*/
-@SpringBootApplication(exclude = MySQLAutoconfiguration.class)
+@SpringBootApplication
@ServletComponentScan("com.baeldung.annotation.servletcomponentscan.components")
public class SpringBootAnnotatedApp {
diff --git a/spring-boot/src/main/java/com/baeldung/annotation/servletcomponentscan/SpringBootPlainApp.java b/spring-boot/src/main/java/com/baeldung/annotation/servletcomponentscan/SpringBootPlainApp.java
index 580498e831..8a39078aac 100644
--- a/spring-boot/src/main/java/com/baeldung/annotation/servletcomponentscan/SpringBootPlainApp.java
+++ b/spring-boot/src/main/java/com/baeldung/annotation/servletcomponentscan/SpringBootPlainApp.java
@@ -3,9 +3,7 @@ package com.baeldung.annotation.servletcomponentscan;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
-import com.baeldung.autoconfiguration.MySQLAutoconfiguration;
-
-@SpringBootApplication(exclude = MySQLAutoconfiguration.class)
+@SpringBootApplication
@ComponentScan(basePackages = "com.baeldung.annotation.servletcomponentscan.components")
public class SpringBootPlainApp {
diff --git a/spring-boot/src/main/java/com/baeldung/bootcustomfilters/controller/UserController.java b/spring-boot/src/main/java/com/baeldung/bootcustomfilters/controller/UserController.java
index 9dfab1192d..97165f2cf3 100644
--- a/spring-boot/src/main/java/com/baeldung/bootcustomfilters/controller/UserController.java
+++ b/spring-boot/src/main/java/com/baeldung/bootcustomfilters/controller/UserController.java
@@ -6,6 +6,7 @@ import java.util.UUID;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -22,7 +23,7 @@ public class UserController {
private static final Logger LOG = LoggerFactory.getLogger(UserController.class);
- @RequestMapping("")
+ @GetMapping("")
public List getAllUsers() {
LOG.info("Fetching all the users");
return Arrays.asList(
diff --git a/spring-boot/src/main/java/com/baeldung/displayallbeans/controller/FooController.java b/spring-boot/src/main/java/com/baeldung/displayallbeans/controller/FooController.java
index 26f0a60bff..c4a83cc2d9 100644
--- a/spring-boot/src/main/java/com/baeldung/displayallbeans/controller/FooController.java
+++ b/spring-boot/src/main/java/com/baeldung/displayallbeans/controller/FooController.java
@@ -4,7 +4,7 @@ import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.GetMapping;
import com.baeldung.displayallbeans.service.FooService;
@@ -13,7 +13,7 @@ public class FooController {
@Autowired
private FooService fooService;
- @RequestMapping(value = "/displayallbeans")
+ @GetMapping(value = "/displayallbeans")
public String getHeaderAndBody(Map model) {
model.put("header", fooService.getHeader());
model.put("message", fooService.getBody());
diff --git a/spring-boot/src/main/java/com/baeldung/dynamicvalidation/ContactInfoValidator.java b/spring-boot/src/main/java/com/baeldung/dynamicvalidation/ContactInfoValidator.java
index 0f8300a797..e079b9a665 100644
--- a/spring-boot/src/main/java/com/baeldung/dynamicvalidation/ContactInfoValidator.java
+++ b/spring-boot/src/main/java/com/baeldung/dynamicvalidation/ContactInfoValidator.java
@@ -2,7 +2,9 @@ package com.baeldung.dynamicvalidation;
import com.baeldung.dynamicvalidation.dao.ContactInfoExpressionRepository;
import com.baeldung.dynamicvalidation.model.ContactInfoExpression;
-import org.apache.log4j.Logger;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.thymeleaf.util.StringUtils;
@@ -13,7 +15,7 @@ import java.util.regex.Pattern;
public class ContactInfoValidator implements ConstraintValidator {
- private static final Logger LOG = Logger.getLogger(ContactInfoValidator.class);
+ private static final Logger LOG = LogManager.getLogger(ContactInfoValidator.class);
@Autowired
private ContactInfoExpressionRepository expressionRepository;
diff --git a/spring-boot/src/main/java/com/baeldung/dynamicvalidation/DynamicValidationApp.java b/spring-boot/src/main/java/com/baeldung/dynamicvalidation/DynamicValidationApp.java
index acdd836c8c..361a7b1c03 100644
--- a/spring-boot/src/main/java/com/baeldung/dynamicvalidation/DynamicValidationApp.java
+++ b/spring-boot/src/main/java/com/baeldung/dynamicvalidation/DynamicValidationApp.java
@@ -5,9 +5,7 @@ import javax.annotation.security.RolesAllowed;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
-import com.baeldung.autoconfiguration.MySQLAutoconfiguration;
-
-@SpringBootApplication(exclude = MySQLAutoconfiguration.class)
+@SpringBootApplication
public class DynamicValidationApp {
@RolesAllowed("*")
public static void main(String[] args) {
diff --git a/spring-boot/src/main/java/com/baeldung/errorhandling/ErrorHandlingApplication.java b/spring-boot/src/main/java/com/baeldung/errorhandling/ErrorHandlingApplication.java
index 45f9de78e4..5dd55ef077 100644
--- a/spring-boot/src/main/java/com/baeldung/errorhandling/ErrorHandlingApplication.java
+++ b/spring-boot/src/main/java/com/baeldung/errorhandling/ErrorHandlingApplication.java
@@ -1,14 +1,10 @@
package com.baeldung.errorhandling;
-import com.baeldung.autoconfiguration.MySQLAutoconfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
-import org.springframework.web.servlet.handler.HandlerMappingIntrospector;
-@SpringBootApplication(exclude = {MySQLAutoconfiguration.class})
+@SpringBootApplication
@ComponentScan(basePackages = "com.baeldung.errorhandling")
public class ErrorHandlingApplication {
@@ -16,11 +12,4 @@ public class ErrorHandlingApplication {
System.setProperty("spring.profiles.active", "errorhandling");
SpringApplication.run(ErrorHandlingApplication.class, args);
}
-
- @Bean(name = "mvcHandlerMappingIntrospector")
- public HandlerMappingIntrospector mvcHandlerMappingIntrospector(ApplicationContext context) {
- return new HandlerMappingIntrospector(context);
- }
-
-
}
diff --git a/spring-boot/src/main/java/com/baeldung/errorhandling/controllers/MyErrorController.java b/spring-boot/src/main/java/com/baeldung/errorhandling/controllers/MyErrorController.java
index caa335ed23..e002ac045d 100644
--- a/spring-boot/src/main/java/com/baeldung/errorhandling/controllers/MyErrorController.java
+++ b/spring-boot/src/main/java/com/baeldung/errorhandling/controllers/MyErrorController.java
@@ -1,9 +1,9 @@
package com.baeldung.errorhandling.controllers;
-import org.springframework.boot.autoconfigure.web.ErrorController;
+import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.GetMapping;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
@@ -13,7 +13,7 @@ public class MyErrorController implements ErrorController {
public MyErrorController() {}
- @RequestMapping(value = "/error")
+ @GetMapping(value = "/error")
public String handleError(HttpServletRequest request) {
Object status = request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE);
diff --git a/spring-boot/src/main/java/com/baeldung/failureanalyzer/FailureAnalyzerApplication.java b/spring-boot/src/main/java/com/baeldung/failureanalyzer/FailureAnalyzerApplication.java
index 84c96feb92..3489732b6f 100644
--- a/spring-boot/src/main/java/com/baeldung/failureanalyzer/FailureAnalyzerApplication.java
+++ b/spring-boot/src/main/java/com/baeldung/failureanalyzer/FailureAnalyzerApplication.java
@@ -5,9 +5,7 @@ import javax.annotation.security.RolesAllowed;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
-import com.baeldung.autoconfiguration.MySQLAutoconfiguration;
-
-@SpringBootApplication(exclude = MySQLAutoconfiguration.class)
+@SpringBootApplication
public class FailureAnalyzerApplication {
@RolesAllowed("*")
public static void main(String[] args) {
diff --git a/spring-boot/src/main/java/com/baeldung/git/CommitIdApplication.java b/spring-boot/src/main/java/com/baeldung/git/CommitIdApplication.java
index 4655e36f83..cd696eae70 100644
--- a/spring-boot/src/main/java/com/baeldung/git/CommitIdApplication.java
+++ b/spring-boot/src/main/java/com/baeldung/git/CommitIdApplication.java
@@ -6,9 +6,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.io.ClassPathResource;
-import com.baeldung.autoconfiguration.MySQLAutoconfiguration;
-
-@SpringBootApplication(scanBasePackages = { "com.baeldung.git" }, exclude = MySQLAutoconfiguration.class)
+@SpringBootApplication(scanBasePackages = { "com.baeldung.git" })
public class CommitIdApplication {
public static void main(String[] args) {
SpringApplication.run(CommitIdApplication.class, args);
diff --git a/spring-boot/src/main/java/com/baeldung/git/CommitInfoController.java b/spring-boot/src/main/java/com/baeldung/git/CommitInfoController.java
index 6d44e02ec2..9dca749319 100644
--- a/spring-boot/src/main/java/com/baeldung/git/CommitInfoController.java
+++ b/spring-boot/src/main/java/com/baeldung/git/CommitInfoController.java
@@ -1,7 +1,7 @@
package com.baeldung.git;
import org.springframework.beans.factory.annotation.Value;
-import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
@@ -19,7 +19,7 @@ public class CommitInfoController {
@Value("${git.commit.id}")
private String commitId;
- @RequestMapping("/commitId")
+ @GetMapping("/commitId")
public Map getCommitId() {
Map result = new HashMap<>();
result.put("Commit message", commitMessage);
diff --git a/spring-boot/src/main/java/com/baeldung/internationalization/InternationalizationApp.java b/spring-boot/src/main/java/com/baeldung/internationalization/InternationalizationApp.java
index ca56437392..c92d1c32e6 100644
--- a/spring-boot/src/main/java/com/baeldung/internationalization/InternationalizationApp.java
+++ b/spring-boot/src/main/java/com/baeldung/internationalization/InternationalizationApp.java
@@ -5,9 +5,7 @@ import javax.annotation.security.RolesAllowed;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
-import com.baeldung.autoconfiguration.MySQLAutoconfiguration;
-
-@SpringBootApplication(exclude = MySQLAutoconfiguration.class)
+@SpringBootApplication
public class InternationalizationApp {
@RolesAllowed("*")
public static void main(String[] args) {
diff --git a/spring-boot/src/main/java/com/baeldung/internationalization/config/MvcConfig.java b/spring-boot/src/main/java/com/baeldung/internationalization/config/MvcConfig.java
index 8a0b709e69..d93c826cfa 100644
--- a/spring-boot/src/main/java/com/baeldung/internationalization/config/MvcConfig.java
+++ b/spring-boot/src/main/java/com/baeldung/internationalization/config/MvcConfig.java
@@ -7,13 +7,13 @@ import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;
@Configuration
@ComponentScan(basePackages = "com.baeldung.internationalization.config")
-public class MvcConfig extends WebMvcConfigurerAdapter {
+public class MvcConfig implements WebMvcConfigurer {
@Bean
public LocaleResolver localeResolver() {
diff --git a/spring-boot/src/main/java/com/baeldung/intro/App.java b/spring-boot/src/main/java/com/baeldung/intro/App.java
index b865deea29..b5d53f0da3 100644
--- a/spring-boot/src/main/java/com/baeldung/intro/App.java
+++ b/spring-boot/src/main/java/com/baeldung/intro/App.java
@@ -3,9 +3,7 @@ package com.baeldung.intro;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
-import com.baeldung.autoconfiguration.MySQLAutoconfiguration;
-
-@SpringBootApplication(exclude = MySQLAutoconfiguration.class)
+@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
diff --git a/spring-boot/src/main/java/com/baeldung/intro/controller/HomeController.java b/spring-boot/src/main/java/com/baeldung/intro/controller/HomeController.java
index 2a82e58829..32f22f2cae 100644
--- a/spring-boot/src/main/java/com/baeldung/intro/controller/HomeController.java
+++ b/spring-boot/src/main/java/com/baeldung/intro/controller/HomeController.java
@@ -1,17 +1,17 @@
package com.baeldung.intro.controller;
-import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HomeController {
- @RequestMapping("/")
+ @GetMapping("/")
public String root() {
return "Index Page";
}
- @RequestMapping("/local")
+ @GetMapping("/local")
public String local() {
return "/local";
}
diff --git a/spring-boot/src/main/java/com/baeldung/rss/ArticleRssController.java b/spring-boot/src/main/java/com/baeldung/rss/ArticleRssController.java
index a3fbc4a37e..daaeb8159b 100644
--- a/spring-boot/src/main/java/com/baeldung/rss/ArticleRssController.java
+++ b/spring-boot/src/main/java/com/baeldung/rss/ArticleRssController.java
@@ -1,14 +1,14 @@
package com.baeldung.rss;
import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping(value = "/rss", produces = "application/*")
public class ArticleRssController {
- @RequestMapping(method = RequestMethod.GET)
+ @GetMapping
public String articleFeed() {
return "articleFeedView";
}
diff --git a/spring-boot/src/main/java/com/baeldung/rss/CustomContainer.java b/spring-boot/src/main/java/com/baeldung/rss/CustomContainer.java
index ee36ecdc51..aaa3188010 100644
--- a/spring-boot/src/main/java/com/baeldung/rss/CustomContainer.java
+++ b/spring-boot/src/main/java/com/baeldung/rss/CustomContainer.java
@@ -1,16 +1,17 @@
package com.baeldung.rss;
-import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
-import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
+import org.springframework.boot.web.server.WebServerFactoryCustomizer;
+import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.stereotype.Component;
@Component
-public class CustomContainer implements EmbeddedServletContainerCustomizer {
+public class CustomContainer implements WebServerFactoryCustomizer {
@Override
- public void customize(ConfigurableEmbeddedServletContainer container) {
- container.setPort(8080);
- container.setContextPath("");
+ public void customize(ConfigurableServletWebServerFactory factory) {
+ factory.setContextPath("");
+ factory.setPort(8080);
+
}
}
\ No newline at end of file
diff --git a/spring-boot/src/main/java/com/baeldung/rss/RssApp.java b/spring-boot/src/main/java/com/baeldung/rss/RssApp.java
index 2add7ed421..d3d3d0241f 100644
--- a/spring-boot/src/main/java/com/baeldung/rss/RssApp.java
+++ b/spring-boot/src/main/java/com/baeldung/rss/RssApp.java
@@ -1,13 +1,12 @@
package com.baeldung.rss;
-import com.baeldung.autoconfiguration.MySQLAutoconfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import javax.annotation.security.RolesAllowed;
-@SpringBootApplication(exclude = MySQLAutoconfiguration.class)
+@SpringBootApplication
@ComponentScan(basePackages = "com.baeldung.rss")
public class RssApp {
diff --git a/spring-boot/src/main/java/com/baeldung/servletinitializer/WarInitializerApplication.java b/spring-boot/src/main/java/com/baeldung/servletinitializer/WarInitializerApplication.java
index 237026780c..5b9ce1271e 100644
--- a/spring-boot/src/main/java/com/baeldung/servletinitializer/WarInitializerApplication.java
+++ b/spring-boot/src/main/java/com/baeldung/servletinitializer/WarInitializerApplication.java
@@ -5,9 +5,9 @@ import java.time.LocalDateTime;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
-import org.springframework.boot.web.support.SpringBootServletInitializer;
+import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.ui.Model;
-import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@@ -27,7 +27,7 @@ public class WarInitializerApplication extends SpringBootServletInitializer {
@RestController
public static class WarInitializerController {
- @RequestMapping("/")
+ @GetMapping("/")
public String handler(Model model) {
model.addAttribute("date", LocalDateTime.now());
return "WarInitializerApplication is up and running!";
diff --git a/spring-boot/src/main/java/com/baeldung/servlets/ApplicationMain.java b/spring-boot/src/main/java/com/baeldung/servlets/ApplicationMain.java
index c8461e4efc..482e6f4b5a 100644
--- a/spring-boot/src/main/java/com/baeldung/servlets/ApplicationMain.java
+++ b/spring-boot/src/main/java/com/baeldung/servlets/ApplicationMain.java
@@ -3,11 +3,9 @@ package com.baeldung.servlets;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
-import org.springframework.boot.web.support.SpringBootServletInitializer;
+import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
-import com.baeldung.autoconfiguration.MySQLAutoconfiguration;
-
-@SpringBootApplication(exclude = MySQLAutoconfiguration.class)
+@SpringBootApplication
public class ApplicationMain extends SpringBootServletInitializer {
public static void main(String[] args) {
diff --git a/spring-boot/src/main/java/com/baeldung/servlets/configuration/WebMvcConfigure.java b/spring-boot/src/main/java/com/baeldung/servlets/configuration/WebMvcConfigure.java
index 8dea814bc7..e026f5c732 100644
--- a/spring-boot/src/main/java/com/baeldung/servlets/configuration/WebMvcConfigure.java
+++ b/spring-boot/src/main/java/com/baeldung/servlets/configuration/WebMvcConfigure.java
@@ -1,17 +1,17 @@
package com.baeldung.servlets.configuration;
-import org.springframework.boot.web.support.ErrorPageFilter;
+import org.springframework.boot.web.servlet.support.ErrorPageFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.resource.PathResourceResolver;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
@Configuration
-public class WebMvcConfigure extends WebMvcConfigurerAdapter {
+public class WebMvcConfigure implements WebMvcConfigurer {
@Bean
public ViewResolver getViewResolver() {
diff --git a/spring-boot/src/main/java/com/baeldung/servlets/servlets/springboot/SpringRegistrationBeanServlet.java b/spring-boot/src/main/java/com/baeldung/servlets/servlets/springboot/SpringRegistrationBeanServlet.java
index e3c225d429..b34690b75e 100644
--- a/spring-boot/src/main/java/com/baeldung/servlets/servlets/springboot/SpringRegistrationBeanServlet.java
+++ b/spring-boot/src/main/java/com/baeldung/servlets/servlets/springboot/SpringRegistrationBeanServlet.java
@@ -9,8 +9,8 @@ import org.springframework.context.annotation.Configuration;
public class SpringRegistrationBeanServlet {
@Bean
- public ServletRegistrationBean genericCustomServlet() {
- ServletRegistrationBean bean = new ServletRegistrationBean(new GenericCustomServlet(), "/springregistrationbeanservlet/*");
+ public ServletRegistrationBean genericCustomServlet() {
+ ServletRegistrationBean bean = new ServletRegistrationBean<>(new GenericCustomServlet(), "/springregistrationbeanservlet/*");
bean.setLoadOnStartup(1);
return bean;
}
diff --git a/spring-boot/src/main/java/com/baeldung/servlets/servlets/springboot/embedded/EmbeddedTomcatExample.java b/spring-boot/src/main/java/com/baeldung/servlets/servlets/springboot/embedded/EmbeddedTomcatExample.java
index 9e460d03a8..2e7a0d756a 100644
--- a/spring-boot/src/main/java/com/baeldung/servlets/servlets/springboot/embedded/EmbeddedTomcatExample.java
+++ b/spring-boot/src/main/java/com/baeldung/servlets/servlets/springboot/embedded/EmbeddedTomcatExample.java
@@ -1,7 +1,7 @@
package com.baeldung.servlets.servlets.springboot.embedded;
-import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
-import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
+import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
+import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -9,8 +9,8 @@ import org.springframework.context.annotation.Configuration;
public class EmbeddedTomcatExample {
@Bean
- public EmbeddedServletContainerFactory servletContainer() {
- TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
+ public ConfigurableServletWebServerFactory servletContainer() {
+ TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
return tomcat;
}
}
diff --git a/spring-boot/src/main/java/com/baeldung/shutdown/Application.java b/spring-boot/src/main/java/com/baeldung/shutdown/Application.java
index 3d9c71a7b9..2225df8b34 100644
--- a/spring-boot/src/main/java/com/baeldung/shutdown/Application.java
+++ b/spring-boot/src/main/java/com/baeldung/shutdown/Application.java
@@ -1,16 +1,13 @@
package com.baeldung.shutdown;
-import com.baeldung.autoconfiguration.MySQLAutoconfiguration;
-import org.springframework.boot.ExitCodeGenerator;
import org.springframework.boot.SpringApplication;
+import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
-import org.springframework.boot.system.ApplicationPidFileWriter;
+import org.springframework.boot.context.ApplicationPidFileWriter;
import org.springframework.context.ConfigurableApplicationContext;
-import javax.annotation.security.RolesAllowed;
-
-@SpringBootApplication(exclude = MySQLAutoconfiguration.class)
+@SpringBootApplication
public class Application {
public static void main(String[] args) {
@@ -24,7 +21,7 @@ public class Application {
private static void closeApplication() {
- ConfigurableApplicationContext ctx = new SpringApplicationBuilder(Application.class).web(false).run();
+ ConfigurableApplicationContext ctx = new SpringApplicationBuilder(Application.class).web(WebApplicationType.NONE).run();
System.out.println("Spring Boot application started");
ctx.getBean(TerminateBean.class);
ctx.close();
@@ -32,7 +29,7 @@ public class Application {
private static void exitApplication() {
- ConfigurableApplicationContext ctx = new SpringApplicationBuilder(Application.class).web(false).run();
+ ConfigurableApplicationContext ctx = new SpringApplicationBuilder(Application.class).web(WebApplicationType.NONE).run();
int exitCode = SpringApplication.exit(ctx, () -> {
// return the error code
@@ -45,7 +42,7 @@ public class Application {
}
private static void writePID() {
- SpringApplicationBuilder app = new SpringApplicationBuilder(Application.class).web(false);
+ SpringApplicationBuilder app = new SpringApplicationBuilder(Application.class).web(WebApplicationType.NONE);
app.build().addListeners(new ApplicationPidFileWriter("./bin/shutdown.pid"));
app.run();
}
diff --git a/spring-boot/src/main/java/com/baeldung/toggle/FeaturesAspect.java b/spring-boot/src/main/java/com/baeldung/toggle/FeaturesAspect.java
index ed99f65006..04c6305780 100644
--- a/spring-boot/src/main/java/com/baeldung/toggle/FeaturesAspect.java
+++ b/spring-boot/src/main/java/com/baeldung/toggle/FeaturesAspect.java
@@ -1,6 +1,7 @@
package com.baeldung.toggle;
-import org.apache.log4j.Logger;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
@@ -10,7 +11,7 @@ import org.springframework.stereotype.Component;
@Component
public class FeaturesAspect {
- private static final Logger LOG = Logger.getLogger(FeaturesAspect.class);
+ private static final Logger LOG = LogManager.getLogger(FeaturesAspect.class);
@Around(value = "@within(featureAssociation) || @annotation(featureAssociation)")
public Object checkAspect(ProceedingJoinPoint joinPoint, FeatureAssociation featureAssociation) throws Throwable {
diff --git a/spring-boot/src/main/java/com/baeldung/toggle/SalaryService.java b/spring-boot/src/main/java/com/baeldung/toggle/SalaryService.java
index df65033d6b..48a1ddf8d8 100644
--- a/spring-boot/src/main/java/com/baeldung/toggle/SalaryService.java
+++ b/spring-boot/src/main/java/com/baeldung/toggle/SalaryService.java
@@ -11,7 +11,7 @@ public class SalaryService {
@FeatureAssociation(value = MyFeatures.EMPLOYEE_MANAGEMENT_FEATURE)
public void increaseSalary(long id) {
- Employee employee = employeeRepository.findOne(id);
+ Employee employee = employeeRepository.findById(id).orElse(null);
employee.setSalary(employee.getSalary() + employee.getSalary() * 0.1);
employeeRepository.save(employee);
}
diff --git a/spring-boot/src/main/java/com/baeldung/toggle/ToggleApplication.java b/spring-boot/src/main/java/com/baeldung/toggle/ToggleApplication.java
index c269262ab2..27be6b7cca 100644
--- a/spring-boot/src/main/java/com/baeldung/toggle/ToggleApplication.java
+++ b/spring-boot/src/main/java/com/baeldung/toggle/ToggleApplication.java
@@ -5,9 +5,7 @@ import javax.annotation.security.RolesAllowed;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
-import com.baeldung.autoconfiguration.MySQLAutoconfiguration;
-
-@SpringBootApplication(exclude = MySQLAutoconfiguration.class)
+@SpringBootApplication
public class ToggleApplication {
@RolesAllowed("*")
public static void main(String[] args) {
diff --git a/spring-boot/src/main/java/com/baeldung/utils/UtilsApplication.java b/spring-boot/src/main/java/com/baeldung/utils/UtilsApplication.java
index 4b00247c4a..ce3eae7ce0 100644
--- a/spring-boot/src/main/java/com/baeldung/utils/UtilsApplication.java
+++ b/spring-boot/src/main/java/com/baeldung/utils/UtilsApplication.java
@@ -6,9 +6,7 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
-import com.baeldung.autoconfiguration.MySQLAutoconfiguration;
-
-@SpringBootApplication(exclude = MySQLAutoconfiguration.class)
+@SpringBootApplication
@ComponentScan(basePackages = "com.baeldung.utils")
public class UtilsApplication {
diff --git a/spring-boot/src/main/java/com/baeldung/webjar/TestController.java b/spring-boot/src/main/java/com/baeldung/webjar/TestController.java
index e8e7fd5ce9..e5404c7c7c 100644
--- a/spring-boot/src/main/java/com/baeldung/webjar/TestController.java
+++ b/spring-boot/src/main/java/com/baeldung/webjar/TestController.java
@@ -2,12 +2,12 @@ package com.baeldung.webjar;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
-import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class TestController {
- @RequestMapping(value = "/")
+ @GetMapping(value = "/")
public String welcome(Model model) {
return "index";
}
diff --git a/spring-boot/src/main/java/com/baeldung/webjar/WebjarsdemoApplication.java b/spring-boot/src/main/java/com/baeldung/webjar/WebjarsdemoApplication.java
index 5038c7e5f7..2397861f1d 100644
--- a/spring-boot/src/main/java/com/baeldung/webjar/WebjarsdemoApplication.java
+++ b/spring-boot/src/main/java/com/baeldung/webjar/WebjarsdemoApplication.java
@@ -3,9 +3,7 @@ package com.baeldung.webjar;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
-import com.baeldung.autoconfiguration.MySQLAutoconfiguration;
-
-@SpringBootApplication(exclude = MySQLAutoconfiguration.class)
+@SpringBootApplication
public class WebjarsdemoApplication {
public static void main(String[] args) {
diff --git a/spring-boot/src/main/java/org/baeldung/boot/Application.java b/spring-boot/src/main/java/org/baeldung/boot/Application.java
index 78e95455b8..c1b6558b26 100644
--- a/spring-boot/src/main/java/org/baeldung/boot/Application.java
+++ b/spring-boot/src/main/java/org/baeldung/boot/Application.java
@@ -4,9 +4,7 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
-import com.baeldung.autoconfiguration.MySQLAutoconfiguration;
-
-@SpringBootApplication(exclude = MySQLAutoconfiguration.class)
+@SpringBootApplication
public class Application {
private static ApplicationContext applicationContext;
diff --git a/spring-boot/src/main/java/org/baeldung/boot/config/WebConfig.java b/spring-boot/src/main/java/org/baeldung/boot/config/WebConfig.java
index caf88c3be7..6d8708b06a 100644
--- a/spring-boot/src/main/java/org/baeldung/boot/config/WebConfig.java
+++ b/spring-boot/src/main/java/org/baeldung/boot/config/WebConfig.java
@@ -7,12 +7,12 @@ import org.baeldung.boot.web.resolver.HeaderVersionArgumentResolver;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.List;
@Configuration
-public class WebConfig extends WebMvcConfigurerAdapter {
+public class WebConfig implements WebMvcConfigurer {
@Override
public void addArgumentResolvers(final List argumentResolvers) {
diff --git a/spring-boot/src/main/java/org/baeldung/boot/controller/GenericEntityController.java b/spring-boot/src/main/java/org/baeldung/boot/controller/GenericEntityController.java
index 817bae8d01..17457f4c20 100644
--- a/spring-boot/src/main/java/org/baeldung/boot/controller/GenericEntityController.java
+++ b/spring-boot/src/main/java/org/baeldung/boot/controller/GenericEntityController.java
@@ -7,8 +7,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDateTime;
@@ -26,18 +25,18 @@ public class GenericEntityController {
entityList.add(new GenericEntity(4l, "entity_4"));
}
- @RequestMapping("/entity/all")
+ @GetMapping("/entity/all")
public List findAll() {
return entityList;
}
- @RequestMapping(value = "/entity", method = RequestMethod.POST)
+ @PostMapping("/entity")
public GenericEntity addEntity(GenericEntity entity) {
entityList.add(entity);
return entity;
}
- @RequestMapping("/entity/findby/{id}")
+ @GetMapping("/entity/findby/{id}")
public GenericEntity findById(@PathVariable Long id) {
return entityList.stream().filter(entity -> entity.getId().equals(id)).findFirst().get();
}
diff --git a/spring-boot/src/main/java/org/baeldung/common/error/MyCustomErrorController.java b/spring-boot/src/main/java/org/baeldung/common/error/MyCustomErrorController.java
index 510e607dfa..e4e20de671 100644
--- a/spring-boot/src/main/java/org/baeldung/common/error/MyCustomErrorController.java
+++ b/spring-boot/src/main/java/org/baeldung/common/error/MyCustomErrorController.java
@@ -1,7 +1,7 @@
package org.baeldung.common.error;
-import org.springframework.boot.autoconfigure.web.ErrorController;
-import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.boot.web.servlet.error.ErrorController;
+import org.springframework.web.bind.annotation.GetMapping;
public class MyCustomErrorController implements ErrorController {
@@ -11,7 +11,7 @@ public class MyCustomErrorController implements ErrorController {
// TODO Auto-generated constructor stub
}
- @RequestMapping(value = PATH)
+ @GetMapping(value = PATH)
public String error() {
return "Error heaven";
}
diff --git a/spring-boot/src/main/java/org/baeldung/common/error/controller/ErrorController.java b/spring-boot/src/main/java/org/baeldung/common/error/controller/ErrorController.java
index ecabde7d9d..d503f5da6d 100644
--- a/spring-boot/src/main/java/org/baeldung/common/error/controller/ErrorController.java
+++ b/spring-boot/src/main/java/org/baeldung/common/error/controller/ErrorController.java
@@ -1,6 +1,6 @@
package org.baeldung.common.error.controller;
-import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@@ -9,12 +9,12 @@ public class ErrorController {
public ErrorController() {
}
- @RequestMapping("/400")
+ @GetMapping("/400")
String error400() {
return "Error Code: 400 occured.";
}
- @RequestMapping("/errorHeaven")
+ @GetMapping("/errorHeaven")
String errorHeaven() {
return "You have reached the heaven of errors!!!";
}
diff --git a/spring-boot/src/main/java/org/baeldung/common/properties/MyServletContainerCustomizationBean.java b/spring-boot/src/main/java/org/baeldung/common/properties/MyServletContainerCustomizationBean.java
index 9b5a0aa948..2d955bac9b 100644
--- a/spring-boot/src/main/java/org/baeldung/common/properties/MyServletContainerCustomizationBean.java
+++ b/spring-boot/src/main/java/org/baeldung/common/properties/MyServletContainerCustomizationBean.java
@@ -1,20 +1,20 @@
package org.baeldung.common.properties;
-import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
-import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
-import org.springframework.boot.web.servlet.ErrorPage;
+import org.springframework.boot.web.server.ErrorPage;
+import org.springframework.boot.web.server.WebServerFactoryCustomizer;
+import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
@Component
-public class MyServletContainerCustomizationBean implements EmbeddedServletContainerCustomizer {
+public class MyServletContainerCustomizationBean implements WebServerFactoryCustomizer {
public MyServletContainerCustomizationBean() {
}
@Override
- public void customize(ConfigurableEmbeddedServletContainer container) {
+ public void customize(ConfigurableServletWebServerFactory container) {
container.setPort(8084);
container.setContextPath("/springbootapp");
diff --git a/spring-boot/src/main/java/org/baeldung/demo/DemoApplication.java b/spring-boot/src/main/java/org/baeldung/demo/DemoApplication.java
index c4b0d48244..4a88fcea07 100644
--- a/spring-boot/src/main/java/org/baeldung/demo/DemoApplication.java
+++ b/spring-boot/src/main/java/org/baeldung/demo/DemoApplication.java
@@ -4,10 +4,9 @@ import com.baeldung.graphql.GraphqlConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
-import com.baeldung.autoconfiguration.MySQLAutoconfiguration;
import org.springframework.context.annotation.Import;
-@SpringBootApplication(exclude = MySQLAutoconfiguration.class)
+@SpringBootApplication
@Import(GraphqlConfiguration.class)
public class DemoApplication {
diff --git a/spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeRepository.java b/spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeRepository.java
index d991d9a8a9..00fdbfaae4 100644
--- a/spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeRepository.java
+++ b/spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeRepository.java
@@ -2,10 +2,9 @@ package org.baeldung.demo.boottest;
import java.util.List;
-import javax.transaction.Transactional;
-
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
@Repository
@Transactional
@@ -13,8 +12,6 @@ public interface EmployeeRepository extends JpaRepository {
public Employee findByName(String name);
- public Employee findById(Long id);
-
public List findAll();
}
diff --git a/spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeServiceImpl.java b/spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeServiceImpl.java
index bd85234e02..a1639b29cc 100644
--- a/spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeServiceImpl.java
+++ b/spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeServiceImpl.java
@@ -2,10 +2,9 @@ package org.baeldung.demo.boottest;
import java.util.List;
-import javax.transaction.Transactional;
-
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
@Service
@Transactional
@@ -16,7 +15,7 @@ public class EmployeeServiceImpl implements EmployeeService {
@Override
public Employee getEmployeeById(Long id) {
- return employeeRepository.findById(id);
+ return employeeRepository.findById(id).orElse(null);
}
@Override
diff --git a/spring-boot/src/main/java/org/baeldung/demo/components/FooService.java b/spring-boot/src/main/java/org/baeldung/demo/components/FooService.java
index 334730ccb0..66943f6461 100644
--- a/spring-boot/src/main/java/org/baeldung/demo/components/FooService.java
+++ b/spring-boot/src/main/java/org/baeldung/demo/components/FooService.java
@@ -12,7 +12,7 @@ public class FooService {
private FooRepository fooRepository;
public Foo getFooWithId(Integer id) throws Exception {
- return fooRepository.findOne(id);
+ return fooRepository.findById(id).orElse(null);
}
public Foo getFooWithName(String name) {
diff --git a/spring-boot/src/main/java/org/baeldung/endpoints/CustomEndpoint.java b/spring-boot/src/main/java/org/baeldung/endpoints/CustomEndpoint.java
deleted file mode 100644
index 222a54c6ef..0000000000
--- a/spring-boot/src/main/java/org/baeldung/endpoints/CustomEndpoint.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package org.baeldung.endpoints;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.springframework.boot.actuate.endpoint.Endpoint;
-import org.springframework.stereotype.Component;
-
-@Component
-public class CustomEndpoint implements Endpoint> {
-
- public CustomEndpoint() {
-
- }
-
- public String getId() {
- return "customEndpoint";
- }
-
- public boolean isEnabled() {
- return true;
- }
-
- public boolean isSensitive() {
- return true;
- }
-
- public List invoke() {
- // Your logic to display the output
- List messages = new ArrayList();
- messages.add("This is message 1");
- messages.add("This is message 2");
- return messages;
- }
-}
diff --git a/spring-boot/src/main/java/org/baeldung/endpoints/ListEndpoints.java b/spring-boot/src/main/java/org/baeldung/endpoints/ListEndpoints.java
deleted file mode 100644
index 61571b4adf..0000000000
--- a/spring-boot/src/main/java/org/baeldung/endpoints/ListEndpoints.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package org.baeldung.endpoints;
-
-import java.util.List;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.actuate.endpoint.AbstractEndpoint;
-import org.springframework.boot.actuate.endpoint.Endpoint;
-import org.springframework.stereotype.Component;
-
-@Component
-public class ListEndpoints extends AbstractEndpoint> {
- private List endpoints;
-
- @Autowired
- public ListEndpoints(List endpoints) {
- super("listEndpoints");
- this.endpoints = endpoints;
- }
-
- public List invoke() {
- return this.endpoints;
- }
-}
\ No newline at end of file
diff --git a/spring-boot/src/main/java/org/baeldung/endpoints/MyHealthCheck.java b/spring-boot/src/main/java/org/baeldung/endpoints/MyHealthCheck.java
deleted file mode 100644
index 1a175aed48..0000000000
--- a/spring-boot/src/main/java/org/baeldung/endpoints/MyHealthCheck.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package org.baeldung.endpoints;
-
-import org.springframework.boot.actuate.health.Health;
-import org.springframework.boot.actuate.health.HealthIndicator;
-import org.springframework.stereotype.Component;
-
-@Component
-public class MyHealthCheck implements HealthIndicator {
-
- public Health health() {
- int errorCode = check(); // perform some specific health check
- if (errorCode != 0) {
- return Health.down().withDetail("Error Code", errorCode).withDetail("Description", "You custom MyHealthCheck endpoint is down").build();
- }
- return Health.up().build();
- }
-
- public int check() {
- // Your logic to check health
- return 1;
- }
-}
diff --git a/spring-boot/src/main/java/org/baeldung/main/SpringBootApplication.java b/spring-boot/src/main/java/org/baeldung/main/SpringBootApplication.java
index 5cc697be65..30ac94221b 100644
--- a/spring-boot/src/main/java/org/baeldung/main/SpringBootApplication.java
+++ b/spring-boot/src/main/java/org/baeldung/main/SpringBootApplication.java
@@ -4,34 +4,27 @@ import org.baeldung.boot.controller.servlet.HelloWorldServlet;
import org.baeldung.boot.controller.servlet.SpringHelloWorldServlet;
import org.baeldung.common.error.SpringHelloServletRegistrationBean;
import org.baeldung.common.resources.ExecutorServiceExitCodeGenerator;
-import org.baeldung.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
-import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
-import com.baeldung.autoconfiguration.MySQLAutoconfiguration;
-
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@RestController
-@EnableAutoConfiguration(exclude = MySQLAutoconfiguration.class)
+@EnableAutoConfiguration
@ComponentScan({ "org.baeldung.common.error", "org.baeldung.common.error.controller", "org.baeldung.common.properties", "org.baeldung.common.resources", "org.baeldung.endpoints", "org.baeldung.service", "org.baeldung.monitor.jmx", "org.baeldung.boot.config" })
public class SpringBootApplication {
private static ApplicationContext applicationContext;
- @Autowired
- private LoginService service;
-
- @RequestMapping("/")
+ @GetMapping("/")
String home() {
- service.login("admin", "admin".toCharArray());
return "TADA!!! You are in Spring Boot Actuator test application.";
}
diff --git a/spring-boot/src/main/java/org/baeldung/properties/ConfigPropertiesDemoApplication.java b/spring-boot/src/main/java/org/baeldung/properties/ConfigPropertiesDemoApplication.java
index 8ebda17f7d..cb0304fc41 100644
--- a/spring-boot/src/main/java/org/baeldung/properties/ConfigPropertiesDemoApplication.java
+++ b/spring-boot/src/main/java/org/baeldung/properties/ConfigPropertiesDemoApplication.java
@@ -4,9 +4,7 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
-import com.baeldung.autoconfiguration.MySQLAutoconfiguration;
-
-@EnableAutoConfiguration(exclude = MySQLAutoconfiguration.class)
+@EnableAutoConfiguration
@ComponentScan(basePackageClasses = ConfigProperties.class)
public class ConfigPropertiesDemoApplication {
public static void main(String[] args) {
diff --git a/spring-boot/src/main/java/org/baeldung/service/LoginService.java b/spring-boot/src/main/java/org/baeldung/service/LoginService.java
deleted file mode 100644
index 4f38e9cf09..0000000000
--- a/spring-boot/src/main/java/org/baeldung/service/LoginService.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package org.baeldung.service;
-
-public interface LoginService {
- public boolean login(String userName, char[] password);
-}
diff --git a/spring-boot/src/main/java/org/baeldung/service/LoginServiceImpl.java b/spring-boot/src/main/java/org/baeldung/service/LoginServiceImpl.java
deleted file mode 100644
index ed0090f8e4..0000000000
--- a/spring-boot/src/main/java/org/baeldung/service/LoginServiceImpl.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package org.baeldung.service;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.actuate.metrics.CounterService;
-import org.springframework.stereotype.Service;
-
-@Service
-public class LoginServiceImpl implements LoginService {
-
- private CounterService counterService;
-
- @Autowired
- public LoginServiceImpl(CounterService counterService) {
- this.counterService = counterService;
- }
-
- public boolean login(String userName, char[] password) {
- boolean success;
- if (userName.equals("admin") && "secret".toCharArray().equals(password)) {
- counterService.increment("counter.login.success");
- success = true;
- } else {
- counterService.increment("counter.login.failure");
- success = false;
- }
- return success;
- }
-
-}
diff --git a/spring-boot/src/main/java/org/baeldung/session/exception/Application.java b/spring-boot/src/main/java/org/baeldung/session/exception/Application.java
index 70c68368b5..9132e710d1 100644
--- a/spring-boot/src/main/java/org/baeldung/session/exception/Application.java
+++ b/spring-boot/src/main/java/org/baeldung/session/exception/Application.java
@@ -7,10 +7,8 @@ import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.Bean;
import org.springframework.orm.jpa.vendor.HibernateJpaSessionFactoryBean;
-import com.baeldung.autoconfiguration.MySQLAutoconfiguration;
-
@EntityScan(basePackageClasses = Foo.class)
-@SpringBootApplication(exclude = MySQLAutoconfiguration.class)
+@SpringBootApplication
public class Application {
public static void main(String[] args) {
System.setProperty("spring.config.name", "exception");
diff --git a/spring-boot/src/main/java/org/baeldung/websocket/client/MyStompSessionHandler.java b/spring-boot/src/main/java/org/baeldung/websocket/client/MyStompSessionHandler.java
index 45fbf2b623..92beab9430 100644
--- a/spring-boot/src/main/java/org/baeldung/websocket/client/MyStompSessionHandler.java
+++ b/spring-boot/src/main/java/org/baeldung/websocket/client/MyStompSessionHandler.java
@@ -1,6 +1,7 @@
package org.baeldung.websocket.client;
-import org.apache.log4j.Logger;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.springframework.messaging.simp.stomp.StompCommand;
import org.springframework.messaging.simp.stomp.StompHeaders;
import org.springframework.messaging.simp.stomp.StompSession;
@@ -18,7 +19,7 @@ import java.lang.reflect.Type;
*/
public class MyStompSessionHandler extends StompSessionHandlerAdapter {
- private Logger logger = Logger.getLogger(MyStompSessionHandler.class);
+ private Logger logger = LogManager.getLogger(MyStompSessionHandler.class);
@Override
public void afterConnected(StompSession session, StompHeaders connectedHeaders) {
diff --git a/spring-boot/src/main/resources/application.properties b/spring-boot/src/main/resources/application.properties
index 203f0ee3c5..04a4fbf9de 100644
--- a/spring-boot/src/main/resources/application.properties
+++ b/spring-boot/src/main/resources/application.properties
@@ -1,21 +1,22 @@
server.port=9090
-server.contextPath=/springbootapp
-management.port=8081
-management.address=127.0.0.1
+server.servlet.contextPath=/springbootapp
+management.server.port=8081
+management.server.address=127.0.0.1
#debug=true
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto = update
-endpoints.shutdown.enabled=true
-endpoints.jmx.domain=Spring Sample Application
-endpoints.jmx.uniqueNames=true
+management.endpoints.jmx.domain=Spring Sample Application
+management.endpoints.jmx.uniqueNames=true
+
+management.endpoint.shutdown.enabled=true
##jolokia.config.debug=true
##endpoints.jolokia.enabled=true
##endpoints.jolokia.path=jolokia
spring.jmx.enabled=true
-endpoints.jmx.enabled=true
+management.endpoints.jmx.enabled=true
## for pretty printing of json when endpoints accessed over HTTP
http.mappers.jsonPrettyPrint=true
@@ -26,11 +27,7 @@ info.app.description=This is my first spring boot application G1
info.app.version=1.0.0
info.java-vendor = ${java.specification.vendor}
-## Spring Security Configurations
-security.user.name=admin1
-security.user.password=secret1
management.security.role=SUPERUSER
-management.endpoint.shutdown.enabled=true
logging.level.org.springframework=INFO
@@ -38,15 +35,12 @@ logging.level.org.springframework=INFO
servlet.name=dispatcherExample
servlet.mapping=/dispatcherExampleURL
-#banner.charset=UTF-8
-#banner.location=classpath:banner.txt
-#banner.image.location=classpath:banner.gif
-#banner.image.width= //TODO
-#banner.image.height= //TODO
-#banner.image.margin= //TODO
-#banner.image.invert= //TODO
+#spring.banner.charset=UTF-8
+#spring.banner.location=classpath:banner.txt
+#spring.banner.image.location=classpath:banner.gif
+#spring.banner.image.width= //TODO
+#spring.banner.image.height= //TODO
+#spring.banner.image.margin= //TODO
+#spring.banner.image.invert= //TODO
contactInfoType=email
-
-endpoints.beans.id=springbeans
-endpoints.beans.sensitive=false
diff --git a/spring-boot/src/test/java/com/baeldung/displayallbeans/DisplayBeanIntegrationTest.java b/spring-boot/src/test/java/com/baeldung/displayallbeans/DisplayBeanIntegrationTest.java
index afe7f8df31..aab4836b6f 100644
--- a/spring-boot/src/test/java/com/baeldung/displayallbeans/DisplayBeanIntegrationTest.java
+++ b/spring-boot/src/test/java/com/baeldung/displayallbeans/DisplayBeanIntegrationTest.java
@@ -4,9 +4,9 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
-import org.springframework.boot.context.embedded.LocalServerPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
+import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.TestPropertySource;
diff --git a/spring-boot/src/test/java/com/baeldung/servletinitializer/WarInitializerApplicationTest.java b/spring-boot/src/test/java/com/baeldung/servletinitializer/WarInitializerApplicationIntegrationTest.java
similarity index 95%
rename from spring-boot/src/test/java/com/baeldung/servletinitializer/WarInitializerApplicationTest.java
rename to spring-boot/src/test/java/com/baeldung/servletinitializer/WarInitializerApplicationIntegrationTest.java
index a3ee30ef49..2361f422f3 100644
--- a/spring-boot/src/test/java/com/baeldung/servletinitializer/WarInitializerApplicationTest.java
+++ b/spring-boot/src/test/java/com/baeldung/servletinitializer/WarInitializerApplicationIntegrationTest.java
@@ -16,7 +16,7 @@ import com.baeldung.servletinitializer.WarInitializerApplication.WarInitializerC
@RunWith(SpringRunner.class)
@WebMvcTest(controllers = WarInitializerController.class)
-public class WarInitializerApplicationTest {
+public class WarInitializerApplicationIntegrationTest {
@Autowired
private MockMvc mockMvc;
diff --git a/spring-boot/src/test/java/com/baeldung/toggle/ToggleIntegrationTest.java b/spring-boot/src/test/java/com/baeldung/toggle/ToggleIntegrationTest.java
index ca6230e8f5..471565b1c6 100644
--- a/spring-boot/src/test/java/com/baeldung/toggle/ToggleIntegrationTest.java
+++ b/spring-boot/src/test/java/com/baeldung/toggle/ToggleIntegrationTest.java
@@ -47,7 +47,7 @@ public class ToggleIntegrationTest {
mockMvc.perform(post("/increaseSalary").param("id", emp.getId() + "")).andExpect(status().is(200));
- emp = employeeRepository.findOne(1L);
+ emp = employeeRepository.findById(1L).orElse(null);
assertEquals("salary incorrect", 2000, emp.getSalary(), 0.5);
}
@@ -60,7 +60,7 @@ public class ToggleIntegrationTest {
mockMvc.perform(post("/increaseSalary").param("id", emp.getId() + "")).andExpect(status().is(200));
- emp = employeeRepository.findOne(1L);
+ emp = employeeRepository.findById(1L).orElse(null);
assertEquals("salary incorrect", 2200, emp.getSalary(), 0.5);
}
}
diff --git a/spring-boot/src/test/java/org/baeldung/SpringBootH2IntegrationTest.java b/spring-boot/src/test/java/org/baeldung/SpringBootH2IntegrationTest.java
index 2cb2f4dc10..290cfbe081 100644
--- a/spring-boot/src/test/java/org/baeldung/SpringBootH2IntegrationTest.java
+++ b/spring-boot/src/test/java/org/baeldung/SpringBootH2IntegrationTest.java
@@ -22,7 +22,7 @@ public class SpringBootH2IntegrationTest {
@Test
public void givenGenericEntityRepository_whenSaveAndRetreiveEntity_thenOK() {
GenericEntity genericEntity = genericEntityRepository.save(new GenericEntity("test"));
- GenericEntity foundEntity = genericEntityRepository.findOne(genericEntity.getId());
+ GenericEntity foundEntity = genericEntityRepository.findById(genericEntity.getId()).orElse(null);
assertNotNull(foundEntity);
assertEquals(genericEntity.getValue(), foundEntity.getValue());
}
diff --git a/spring-boot/src/test/java/org/baeldung/SpringBootJPAIntegrationTest.java b/spring-boot/src/test/java/org/baeldung/SpringBootJPAIntegrationTest.java
index d9c30c67da..c368cf5219 100644
--- a/spring-boot/src/test/java/org/baeldung/SpringBootJPAIntegrationTest.java
+++ b/spring-boot/src/test/java/org/baeldung/SpringBootJPAIntegrationTest.java
@@ -21,7 +21,7 @@ public class SpringBootJPAIntegrationTest {
@Test
public void givenGenericEntityRepository_whenSaveAndRetreiveEntity_thenOK() {
GenericEntity genericEntity = genericEntityRepository.save(new GenericEntity("test"));
- GenericEntity foundEntity = genericEntityRepository.findOne(genericEntity.getId());
+ GenericEntity foundEntity = genericEntityRepository.findById(genericEntity.getId()).orElse(null);
assertNotNull(foundEntity);
assertEquals(genericEntity.getValue(), foundEntity.getValue());
}
diff --git a/spring-boot/src/test/java/org/baeldung/SpringBootProfileIntegrationTest.java b/spring-boot/src/test/java/org/baeldung/SpringBootProfileIntegrationTest.java
index 1d4ee262b0..128a05f103 100644
--- a/spring-boot/src/test/java/org/baeldung/SpringBootProfileIntegrationTest.java
+++ b/spring-boot/src/test/java/org/baeldung/SpringBootProfileIntegrationTest.java
@@ -24,7 +24,7 @@ public class SpringBootProfileIntegrationTest {
@Test
public void givenGenericEntityRepository_whenSaveAndRetreiveEntity_thenOK() {
GenericEntity genericEntity = genericEntityRepository.save(new GenericEntity("test"));
- GenericEntity foundEntity = genericEntityRepository.findOne(genericEntity.getId());
+ GenericEntity foundEntity = genericEntityRepository.findById(genericEntity.getId()).orElse(null);
assertNotNull(foundEntity);
assertEquals(genericEntity.getValue(), foundEntity.getValue());
}
diff --git a/spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeRepositoryIntegrationTest.java b/spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeRepositoryIntegrationTest.java
index f581052596..3042f95a46 100644
--- a/spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeRepositoryIntegrationTest.java
+++ b/spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeRepositoryIntegrationTest.java
@@ -43,13 +43,13 @@ public class EmployeeRepositoryIntegrationTest {
Employee emp = new Employee("test");
entityManager.persistAndFlush(emp);
- Employee fromDb = employeeRepository.findById(emp.getId());
+ Employee fromDb = employeeRepository.findById(emp.getId()).orElse(null);
assertThat(fromDb.getName()).isEqualTo(emp.getName());
}
@Test
public void whenInvalidId_thenReturnNull() {
- Employee fromDb = employeeRepository.findById(-11L);
+ Employee fromDb = employeeRepository.findById(-11l).orElse(null);
assertThat(fromDb).isNull();
}
diff --git a/spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeServiceImplIntegrationTest.java b/spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeServiceImplIntegrationTest.java
index f004536c49..4eec62db13 100644
--- a/spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeServiceImplIntegrationTest.java
+++ b/spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeServiceImplIntegrationTest.java
@@ -50,9 +50,9 @@ public class EmployeeServiceImplIntegrationTest {
Mockito.when(employeeRepository.findByName(john.getName())).thenReturn(john);
Mockito.when(employeeRepository.findByName(alex.getName())).thenReturn(alex);
Mockito.when(employeeRepository.findByName("wrong_name")).thenReturn(null);
- Mockito.when(employeeRepository.findById(john.getId())).thenReturn(john);
+ Mockito.when(employeeRepository.findById(john.getId()).orElse(null)).thenReturn(john);
Mockito.when(employeeRepository.findAll()).thenReturn(allEmployees);
- Mockito.when(employeeRepository.findById(-99L)).thenReturn(null);
+ Mockito.when(employeeRepository.findById(-99L).orElse(null)).thenReturn(null);
}
@Test
diff --git a/spring-core/pom.xml b/spring-core/pom.xml
index 2fa66a7929..93ff73bb37 100644
--- a/spring-core/pom.xml
+++ b/spring-core/pom.xml
@@ -1,108 +1,104 @@
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- 4.0.0
- com.baeldung
- spring-core
- 0.0.1-SNAPSHOT
- war
- spring-core
+ 4.0.0
+ com.baeldung
+ spring-core
+ 0.0.1-SNAPSHOT
+ war
+ spring-core
-
- com.baeldung
- parent-modules
- 1.0.0-SNAPSHOT
-
+
+ com.baeldung
+ parent-spring
+ 0.0.1-SNAPSHOT
+ ../parent-spring
+
-
-
- org.mockito
- mockito-all
- ${mockito.version}
-
-
- org.springframework
- spring-test
- ${spring.version}
-
-
- org.springframework
- spring-core
- ${spring.version}
-
-
- org.springframework
- spring-beans
- ${spring.version}
-
-
- org.springframework
- spring-context
- ${spring.version}
-
-
- javax.inject
- javax.inject
- ${javax.inject.version}
-
-
- com.google.guava
- guava
- ${guava.version}
-
-
- org.projectlombok
- lombok
- ${lombok.version}
-
-
- org.springframework.boot
- spring-boot-starter
- 1.5.2.RELEASE
-
-
- org.springframework.boot
- spring-boot-test
- ${mockito.spring.boot.version}
- test
-
-
- commons-io
- commons-io
- ${commons.io.version}
-
-
+
+
+ org.mockito
+ mockito-all
+ ${mockito.version}
+
+
+ org.springframework
+ spring-test
+ ${spring.version}
+
+
+ org.springframework
+ spring-beans
+ ${spring.version}
+
+
+ org.springframework
+ spring-context
+ ${spring.version}
+
+
+ javax.inject
+ javax.inject
+ ${javax.inject.version}
+
+
+ com.google.guava
+ guava
+ ${guava.version}
+
+
+ org.projectlombok
+ lombok
+ ${lombok.version}
+
+
+ org.springframework.boot
+ spring-boot-starter
+ 1.5.2.RELEASE
+
+
+ org.springframework.boot
+ spring-boot-test
+ ${mockito.spring.boot.version}
+ test
+
+
+ commons-io
+ commons-io
+ ${commons.io.version}
+
+
-
-
-
- org.apache.maven.plugins
- maven-war-plugin
- ${maven-war-plugin.version}
-
- false
-
-
-
-
+
+
+
+ org.apache.maven.plugins
+ maven-war-plugin
+ ${maven-war-plugin.version}
+
+ false
+
+
+
+
-
- 1.10.19
- 1.4.4.RELEASE
- 4.3.4.RELEASE
- 1
- 20.0
- 2.6
- 1.16.12
- 2.5
-
+
+ 1.10.19
+ 1.4.4.RELEASE
+ 4.3.4.RELEASE
+ 1
+ 20.0
+ 2.6
+ 1.16.12
+ 2.5
+
-
-
- java.net
- https://maven.java.net/content/repositories/releases/
-
-
+
+
+ java.net
+ https://maven.java.net/content/repositories/releases/
+
+
\ No newline at end of file
diff --git a/spring-data-elasticsearch/pom.xml b/spring-data-elasticsearch/pom.xml
index e314e7870e..804cf23a69 100644
--- a/spring-data-elasticsearch/pom.xml
+++ b/spring-data-elasticsearch/pom.xml
@@ -9,8 +9,9 @@
com.baeldung
- parent-modules
- 1.0.0-SNAPSHOT
+ parent-spring
+ 0.0.1-SNAPSHOT
+ ../parent-spring
diff --git a/spring-data-mongodb/pom.xml b/spring-data-mongodb/pom.xml
index 0ff8f3e9fd..24847aaec6 100644
--- a/spring-data-mongodb/pom.xml
+++ b/spring-data-mongodb/pom.xml
@@ -8,8 +8,9 @@
com.baeldung
- parent-modules
- 1.0.0-SNAPSHOT
+ parent-spring
+ 0.0.1-SNAPSHOT
+ ../parent-spring
diff --git a/spring-data-rest/src/main/java/com/baeldung/config/RestConfig.java b/spring-data-rest/src/main/java/com/baeldung/config/RestConfig.java
new file mode 100644
index 0000000000..7434dde394
--- /dev/null
+++ b/spring-data-rest/src/main/java/com/baeldung/config/RestConfig.java
@@ -0,0 +1,17 @@
+package com.baeldung.config;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
+import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurerAdapter;
+
+import com.baeldung.projections.CustomBook;
+
+
+@Configuration
+public class RestConfig extends RepositoryRestConfigurerAdapter{
+
+ @Override
+ public void configureRepositoryRestConfiguration(RepositoryRestConfiguration repositoryRestConfiguration){
+ repositoryRestConfiguration.getProjectionConfiguration().addProjection(CustomBook.class);
+ }
+}
diff --git a/spring-data-rest/src/main/java/com/baeldung/models/Book.java b/spring-data-rest/src/main/java/com/baeldung/models/Book.java
index 06abfb8f4d..002a64e738 100644
--- a/spring-data-rest/src/main/java/com/baeldung/models/Book.java
+++ b/spring-data-rest/src/main/java/com/baeldung/models/Book.java
@@ -4,6 +4,7 @@ import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
+import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@@ -20,12 +21,14 @@ public class Book {
@Column(nullable = false)
private String title;
-
+
+ private String isbn;
+
@ManyToOne
@JoinColumn(name = "library_id")
private Library library;
- @ManyToMany(mappedBy = "books")
+ @ManyToMany(mappedBy = "books", fetch = FetchType.EAGER)
private List authors;
public Book() {
@@ -52,6 +55,15 @@ public class Book {
this.id = id;
}
+ public String getIsbn() {
+ return isbn;
+ }
+
+ public void setIsbn(String isbn) {
+ this.isbn = isbn;
+ }
+
+
public Library getLibrary() {
return library;
}
diff --git a/spring-data-rest/src/main/java/com/baeldung/projections/CustomBook.java b/spring-data-rest/src/main/java/com/baeldung/projections/CustomBook.java
new file mode 100644
index 0000000000..1cd9c01383
--- /dev/null
+++ b/spring-data-rest/src/main/java/com/baeldung/projections/CustomBook.java
@@ -0,0 +1,22 @@
+package com.baeldung.projections;
+
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.data.rest.core.config.Projection;
+
+import com.baeldung.models.Author;
+import com.baeldung.models.Book;
+
+@Projection(name = "customBook", types = { Book.class })
+public interface CustomBook {
+ @Value("#{target.id}")
+ long getId();
+
+ String getTitle();
+
+ List getAuthors();
+
+ @Value("#{target.getAuthors().size()}")
+ int getAuthorCount();
+}
diff --git a/spring-data-rest/src/main/java/com/baeldung/repositories/BookRepository.java b/spring-data-rest/src/main/java/com/baeldung/repositories/BookRepository.java
index f9176032ab..34019a9d91 100644
--- a/spring-data-rest/src/main/java/com/baeldung/repositories/BookRepository.java
+++ b/spring-data-rest/src/main/java/com/baeldung/repositories/BookRepository.java
@@ -1,9 +1,10 @@
package com.baeldung.repositories;
import org.springframework.data.repository.CrudRepository;
+import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import com.baeldung.models.Book;
+import com.baeldung.projections.CustomBook;
-public interface BookRepository extends CrudRepository {
-
-}
+@RepositoryRestResource(excerptProjection = CustomBook.class)
+public interface BookRepository extends CrudRepository {}
diff --git a/spring-data-rest/src/test/java/com/baeldung/projection/SpringDataProjectionIntegrationTest.java b/spring-data-rest/src/test/java/com/baeldung/projection/SpringDataProjectionIntegrationTest.java
new file mode 100644
index 0000000000..4091fdf154
--- /dev/null
+++ b/spring-data-rest/src/test/java/com/baeldung/projection/SpringDataProjectionIntegrationTest.java
@@ -0,0 +1,92 @@
+package com.baeldung.projection;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import io.restassured.RestAssured;
+import io.restassured.response.Response;
+
+import java.util.Arrays;
+
+import org.junit.Before;
+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.boot.test.context.SpringBootTest.WebEnvironment;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import com.baeldung.SpringDataRestApplication;
+import com.baeldung.models.Author;
+import com.baeldung.models.Book;
+import com.baeldung.repositories.AuthorRepository;
+import com.baeldung.repositories.BookRepository;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = SpringDataRestApplication.class, webEnvironment = WebEnvironment.DEFINED_PORT)
+
+public class SpringDataProjectionIntegrationTest {
+ private static final String BOOK_ENDPOINT = "http://localhost:8080/books";
+ private static final String AUTHOR_ENDPOINT = "http://localhost:8080/authors";
+
+
+ @Autowired
+ private BookRepository bookRepo;
+
+ @Autowired
+ private AuthorRepository authorRepo;
+
+ @Before
+ public void setup(){
+ if(bookRepo.findOne(1L) == null){
+ Book book = new Book("Animal Farm");
+ book.setIsbn("978-1943138425");
+ book = bookRepo.save(book);
+ Author author = new Author("George Orwell");
+ author = authorRepo.save(author);
+ author.setBooks(Arrays.asList(book));
+ author = authorRepo.save(author);
+ }
+ }
+
+ @Test
+ public void whenGetBook_thenOK(){
+ final Response response = RestAssured.get(BOOK_ENDPOINT+"/1");
+
+ assertEquals(200, response.getStatusCode());
+ assertTrue(response.asString().contains("isbn"));
+ assertFalse(response.asString().contains("authorCount"));
+// System.out.println(response.asString());
+ }
+
+
+ @Test
+ public void whenGetBookProjection_thenOK(){
+ final Response response = RestAssured.get(BOOK_ENDPOINT+"/1?projection=customBook");
+
+ assertEquals(200, response.getStatusCode());
+ assertFalse(response.asString().contains("isbn"));
+ assertTrue(response.asString().contains("authorCount"));
+// System.out.println(response.asString());
+ }
+
+ @Test
+ public void whenGetAllBooks_thenOK(){
+ final Response response = RestAssured.get(BOOK_ENDPOINT);
+
+ assertEquals(200, response.getStatusCode());
+ assertFalse(response.asString().contains("isbn"));
+ assertTrue(response.asString().contains("authorCount"));
+ // System.out.println(response.asString());
+ }
+
+ @Test
+ public void whenGetAuthorBooks_thenOK(){
+ final Response response = RestAssured.get(AUTHOR_ENDPOINT+"/1/books");
+
+ assertEquals(200, response.getStatusCode());
+ assertFalse(response.asString().contains("isbn"));
+ assertTrue(response.asString().contains("authorCount"));
+ System.out.println(response.asString());
+ }
+}
diff --git a/spring-dispatcher-servlet/pom.xml b/spring-dispatcher-servlet/pom.xml
index 1d4d2b0d71..9fa02f157d 100644
--- a/spring-dispatcher-servlet/pom.xml
+++ b/spring-dispatcher-servlet/pom.xml
@@ -1,102 +1,98 @@
- 4.0.0
- com.baeldung
- spring-dispatcher-servlet
- war
- 1.0.0
- spring-dispatcher-servlet
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+ xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ 4.0.0
+ com.baeldung
+ spring-dispatcher-servlet
+ war
+ 1.0.0
+ spring-dispatcher-servlet
-
- com.baeldung
- parent-modules
- 1.0.0-SNAPSHOT
-
+
+ com.baeldung
+ parent-spring
+ 0.0.1-SNAPSHOT
+ ../parent-spring
+
-
-
- org.springframework
- spring-core
- ${springframework.version}
-
-
- org.springframework
- spring-web
- ${springframework.version}
-
-
- org.springframework
- spring-webmvc
- ${springframework.version}
-
-
- javax.servlet
- javax.servlet-api
- ${javax.servlet-api.version}
-
-
- javax.servlet.jsp.jstl
- jstl-api
- ${jstl-api.version}
-
-
- javax.servlet.jsp
- javax.servlet.jsp-api
- ${javax.servlet.jsp-api.version}
-
-
- org.codehaus.jackson
- jackson-mapper-asl
- ${jackson-mapper-asl.version}
-
-
- javax.servlet
- jstl
- ${jstl.version}
-
-
- com.fasterxml.jackson.core
- jackson-databind
- ${jackson-databind.version}
-
-
- commons-fileupload
- commons-fileupload
- ${commons-fileupload.version}
-
-
+
+
+ org.springframework
+ spring-web
+ ${spring.version}
+
+
+ org.springframework
+ spring-webmvc
+ ${spring.version}
+
+
+ javax.servlet
+ javax.servlet-api
+ ${javax.servlet-api.version}
+
+
+ javax.servlet.jsp.jstl
+ jstl-api
+ ${jstl-api.version}
+
+
+ javax.servlet.jsp
+ javax.servlet.jsp-api
+ ${javax.servlet.jsp-api.version}
+
+
+ org.codehaus.jackson
+ jackson-mapper-asl
+ ${jackson-mapper-asl.version}
+
+
+ javax.servlet
+ jstl
+ ${jstl.version}
+
+
+ com.fasterxml.jackson.core
+ jackson-databind
+ ${jackson-databind.version}
+
+
+ commons-fileupload
+ commons-fileupload
+ ${commons-fileupload.version}
+
+
-
- spring-dispatcher-servlet
-
-
-
- org.apache.tomcat.maven
- tomcat8-maven-plugin
- ${tomcat8-maven-plugin.version}
-
- /springdispatcherservlet
-
-
-
- org.apache.maven.plugins
- maven-war-plugin
- ${maven-war-plugin.version}
-
- src/main/webapp
- false
-
-
-
-
-
+
+ spring-dispatcher-servlet
+
+
+
+ org.apache.tomcat.maven
+ tomcat8-maven-plugin
+ ${tomcat8-maven-plugin.version}
+
+ /springdispatcherservlet
+
+
+
+ org.apache.maven.plugins
+ maven-war-plugin
+ ${maven-war-plugin.version}
+
+ src/main/webapp
+ false
+
+
+
+
+
-
- 4.3.7.RELEASE
- 3.0-r1655215
- 3.0.0
-
+
+ 4.3.7.RELEASE
+ 3.0-r1655215
+ 3.0.0
+
\ No newline at end of file
diff --git a/spring-groovy/pom.xml b/spring-groovy/pom.xml
index f36d6cd22a..eec78d21a6 100644
--- a/spring-groovy/pom.xml
+++ b/spring-groovy/pom.xml
@@ -12,26 +12,12 @@
com.baeldung
- parent-modules
- 1.0.0-SNAPSHOT
+ parent-spring
+ 0.0.1-SNAPSHOT
+ ../parent-spring
-
-
- UTF-8
-
-
+
-
- junit
- junit
- 3.8.1
- test
-
-
- org.springframework
- spring-core
- 4.3.6.RELEASE
-
org.springframework.integration
spring-integration-groovy
@@ -71,4 +57,9 @@
+
+