diff --git a/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletComponentScanRegistrar.java b/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletComponentScanRegistrar.java index 9489d01dc29..5c787edc0de 100644 --- a/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletComponentScanRegistrar.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletComponentScanRegistrar.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot/src/test/java/org/springframework/boot/web/servlet/ServletComponentScanRegistrarTests.java b/spring-boot/src/test/java/org/springframework/boot/web/servlet/ServletComponentScanRegistrarTests.java index 5b1b6d2c80f..8d1ddf8313e 100644 --- a/spring-boot/src/test/java/org/springframework/boot/web/servlet/ServletComponentScanRegistrarTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/web/servlet/ServletComponentScanRegistrarTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -107,6 +107,37 @@ public class ServletComponentScanRegistrarTests { "com.example.bar", "com.example.baz"); } + @Test + public void withNoBasePackagesScanningUsesBasePackageOfAnnotatedClass() { + this.context = new AnnotationConfigApplicationContext(NoBasePackages.class); + ServletComponentRegisteringPostProcessor postProcessor = this.context + .getBean(ServletComponentRegisteringPostProcessor.class); + assertThat(postProcessor.getPackagesToScan()) + .containsExactly("org.springframework.boot.web.servlet"); + } + + @Test + public void noBasePackageAndBasePackageAreCombinedCorrectly() { + this.context = new AnnotationConfigApplicationContext(NoBasePackages.class, + BasePackages.class); + ServletComponentRegisteringPostProcessor postProcessor = this.context + .getBean(ServletComponentRegisteringPostProcessor.class); + assertThat(postProcessor.getPackagesToScan()).containsExactlyInAnyOrder( + "org.springframework.boot.web.servlet", "com.example.foo", + "com.example.bar"); + } + + @Test + public void basePackageAndNoBasePackageAreCombinedCorrectly() { + this.context = new AnnotationConfigApplicationContext(BasePackages.class, + NoBasePackages.class); + ServletComponentRegisteringPostProcessor postProcessor = this.context + .getBean(ServletComponentRegisteringPostProcessor.class); + assertThat(postProcessor.getPackagesToScan()).containsExactlyInAnyOrder( + "org.springframework.boot.web.servlet", "com.example.foo", + "com.example.bar"); + } + @Configuration @ServletComponentScan({ "com.example.foo", "com.example.bar" }) static class ValuePackages { @@ -137,4 +168,10 @@ public class ServletComponentScanRegistrarTests { } + @Configuration + @ServletComponentScan + static class NoBasePackages { + + } + }