diff --git a/pom.xml b/pom.xml index 22f1a82643..3ba6b0c8df 100644 --- a/pom.xml +++ b/pom.xml @@ -10,8 +10,9 @@ parent-boot-5 - parent-spring - parent-java + parent-boot-2 + parent-spring + parent-java asm atomix apache-cayenne 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..09df3b8f02 --- /dev/null +++ b/spring-boot-autoconfiguration/src/main/resources/application.properties @@ -0,0 +1,4 @@ +server.port=9090 + +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/.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/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/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..8bdfea74cd 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,6 +1,6 @@ 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; 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/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/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..1faee5c488 100644 --- a/spring-boot/src/main/java/com/baeldung/servletinitializer/WarInitializerApplication.java +++ b/spring-boot/src/main/java/com/baeldung/servletinitializer/WarInitializerApplication.java @@ -5,7 +5,7 @@ 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.RestController; 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/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/common/error/MyCustomErrorController.java b/spring-boot/src/main/java/org/baeldung/common/error/MyCustomErrorController.java index 510e607dfa..a826a604d3 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,6 +1,6 @@ package org.baeldung.common.error; -import org.springframework.boot.autoconfigure.web.ErrorController; +import org.springframework.boot.web.servlet.error.ErrorController; import org.springframework.web.bind.annotation.RequestMapping; public class MyCustomErrorController implements ErrorController { 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..7d13173be0 100644 --- a/spring-boot/src/main/java/org/baeldung/main/SpringBootApplication.java +++ b/spring-boot/src/main/java/org/baeldung/main/SpringBootApplication.java @@ -4,7 +4,6 @@ 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; @@ -14,24 +13,18 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.web.bind.annotation.RequestMapping; 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("/") 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/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