Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
72cf471e
Commit
72cf471e
authored
Apr 03, 2018
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.5.x'
parents
b6f9b46b
399455f6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
5 deletions
+40
-5
ServletComponentScanRegistrar.java
...ework/boot/web/servlet/ServletComponentScanRegistrar.java
+2
-4
ServletComponentScanRegistrarTests.java
.../boot/web/servlet/ServletComponentScanRegistrarTests.java
+38
-1
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletComponentScanRegistrar.java
View file @
72cf471e
/*
* Copyright 2012-201
7
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -17,7 +17,6 @@
package
org
.
springframework
.
boot
.
web
.
servlet
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.LinkedHashSet
;
import
java.util.Set
;
...
...
@@ -84,8 +83,7 @@ class ServletComponentScanRegistrar implements ImportBeanDefinitionRegistrar {
packagesToScan
.
add
(
ClassUtils
.
getPackageName
(
basePackageClass
));
}
if
(
packagesToScan
.
isEmpty
())
{
return
Collections
.
singleton
(
ClassUtils
.
getPackageName
(
metadata
.
getClassName
()));
packagesToScan
.
add
(
ClassUtils
.
getPackageName
(
metadata
.
getClassName
()));
}
return
packagesToScan
;
}
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/ServletComponentScanRegistrarTests.java
View file @
72cf471e
/*
* Copyright 2012-201
7
the original author or authors.
* Copyright 2012-201
8
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
{
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment