|
1 | 1 | /* |
2 | | - * Copyright 2012-2016 the original author or authors. |
| 2 | + * Copyright 2012-2018 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
@@ -107,6 +107,37 @@ public void packagesFromMultipleAnnotationsAreMerged() { |
107 | 107 | "com.example.bar", "com.example.baz"); |
108 | 108 | } |
109 | 109 |
|
| 110 | + @Test |
| 111 | + public void withNoBasePackagesScanningUsesBasePackageOfAnnotatedClass() { |
| 112 | + this.context = new AnnotationConfigApplicationContext(NoBasePackages.class); |
| 113 | + ServletComponentRegisteringPostProcessor postProcessor = this.context |
| 114 | + .getBean(ServletComponentRegisteringPostProcessor.class); |
| 115 | + assertThat(postProcessor.getPackagesToScan()) |
| 116 | + .containsExactly("org.springframework.boot.web.servlet"); |
| 117 | + } |
| 118 | + |
| 119 | + @Test |
| 120 | + public void noBasePackageAndBasePackageAreCombinedCorrectly() { |
| 121 | + this.context = new AnnotationConfigApplicationContext(NoBasePackages.class, |
| 122 | + BasePackages.class); |
| 123 | + ServletComponentRegisteringPostProcessor postProcessor = this.context |
| 124 | + .getBean(ServletComponentRegisteringPostProcessor.class); |
| 125 | + assertThat(postProcessor.getPackagesToScan()).containsExactlyInAnyOrder( |
| 126 | + "org.springframework.boot.web.servlet", "com.example.foo", |
| 127 | + "com.example.bar"); |
| 128 | + } |
| 129 | + |
| 130 | + @Test |
| 131 | + public void basePackageAndNoBasePackageAreCombinedCorrectly() { |
| 132 | + this.context = new AnnotationConfigApplicationContext(BasePackages.class, |
| 133 | + NoBasePackages.class); |
| 134 | + ServletComponentRegisteringPostProcessor postProcessor = this.context |
| 135 | + .getBean(ServletComponentRegisteringPostProcessor.class); |
| 136 | + assertThat(postProcessor.getPackagesToScan()).containsExactlyInAnyOrder( |
| 137 | + "org.springframework.boot.web.servlet", "com.example.foo", |
| 138 | + "com.example.bar"); |
| 139 | + } |
| 140 | + |
110 | 141 | @Configuration |
111 | 142 | @ServletComponentScan({ "com.example.foo", "com.example.bar" }) |
112 | 143 | static class ValuePackages { |
@@ -137,4 +168,10 @@ static class ValueAndBasePackages { |
137 | 168 |
|
138 | 169 | } |
139 | 170 |
|
| 171 | + @Configuration |
| 172 | + @ServletComponentScan |
| 173 | + static class NoBasePackages { |
| 174 | + |
| 175 | + } |
| 176 | + |
140 | 177 | } |
0 commit comments