Merge branch '1.5.x'
This commit is contained in:
commit
72cf471e83
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -17,7 +17,6 @@
|
||||||
package org.springframework.boot.web.servlet;
|
package org.springframework.boot.web.servlet;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
|
@ -84,8 +83,7 @@ class ServletComponentScanRegistrar implements ImportBeanDefinitionRegistrar {
|
||||||
packagesToScan.add(ClassUtils.getPackageName(basePackageClass));
|
packagesToScan.add(ClassUtils.getPackageName(basePackageClass));
|
||||||
}
|
}
|
||||||
if (packagesToScan.isEmpty()) {
|
if (packagesToScan.isEmpty()) {
|
||||||
return Collections
|
packagesToScan.add(ClassUtils.getPackageName(metadata.getClassName()));
|
||||||
.singleton(ClassUtils.getPackageName(metadata.getClassName()));
|
|
||||||
}
|
}
|
||||||
return packagesToScan;
|
return packagesToScan;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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");
|
"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
|
@Configuration
|
||||||
@ServletComponentScan({ "com.example.foo", "com.example.bar" })
|
@ServletComponentScan({ "com.example.foo", "com.example.bar" })
|
||||||
static class ValuePackages {
|
static class ValuePackages {
|
||||||
|
|
@ -137,4 +168,10 @@ public class ServletComponentScanRegistrarTests {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@ServletComponentScan
|
||||||
|
static class NoBasePackages {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue