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
2b9006b3
Commit
2b9006b3
authored
Feb 12, 2018
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Accumulate config classes across register calls
Closes gh-11998
parent
5e0df39c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
10 deletions
+54
-10
AnnotationConfigReactiveWebServerApplicationContext.java
.../AnnotationConfigReactiveWebServerApplicationContext.java
+11
-4
AnnotationConfigServletWebServerApplicationContext.java
...t/AnnotationConfigServletWebServerApplicationContext.java
+9
-4
AnnotationConfigReactiveWebServerApplicationContextTests.java
...tationConfigReactiveWebServerApplicationContextTests.java
+23
-1
AnnotationConfigServletWebServerApplicationContextTests.java
...otationConfigServletWebServerApplicationContextTests.java
+11
-1
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/AnnotationConfigReactiveWebServerApplicationContext.java
View file @
2b9006b3
...
@@ -16,6 +16,10 @@
...
@@ -16,6 +16,10 @@
package
org
.
springframework
.
boot
.
web
.
reactive
.
context
;
package
org
.
springframework
.
boot
.
web
.
reactive
.
context
;
import
java.util.Arrays
;
import
java.util.LinkedHashSet
;
import
java.util.Set
;
import
org.springframework.beans.factory.config.ConfigurableListableBeanFactory
;
import
org.springframework.beans.factory.config.ConfigurableListableBeanFactory
;
import
org.springframework.beans.factory.support.BeanNameGenerator
;
import
org.springframework.beans.factory.support.BeanNameGenerator
;
import
org.springframework.beans.factory.support.DefaultListableBeanFactory
;
import
org.springframework.beans.factory.support.DefaultListableBeanFactory
;
...
@@ -58,7 +62,7 @@ public class AnnotationConfigReactiveWebServerApplicationContext
...
@@ -58,7 +62,7 @@ public class AnnotationConfigReactiveWebServerApplicationContext
private
final
ClassPathBeanDefinitionScanner
scanner
;
private
final
ClassPathBeanDefinitionScanner
scanner
;
private
Class
<?>[]
annotatedClasses
;
private
final
Set
<
Class
<?>>
annotatedClasses
=
new
LinkedHashSet
<>()
;
private
String
[]
basePackages
;
private
String
[]
basePackages
;
...
@@ -172,10 +176,11 @@ public class AnnotationConfigReactiveWebServerApplicationContext
...
@@ -172,10 +176,11 @@ public class AnnotationConfigReactiveWebServerApplicationContext
* @see #scan(String...)
* @see #scan(String...)
* @see #refresh()
* @see #refresh()
*/
*/
@Override
public
final
void
register
(
Class
<?>...
annotatedClasses
)
{
public
final
void
register
(
Class
<?>...
annotatedClasses
)
{
Assert
.
notEmpty
(
annotatedClasses
,
Assert
.
notEmpty
(
annotatedClasses
,
"At least one annotated class must be specified"
);
"At least one annotated class must be specified"
);
this
.
annotatedClasses
=
annotatedClasses
;
this
.
annotatedClasses
.
addAll
(
Arrays
.
asList
(
annotatedClasses
))
;
}
}
/**
/**
...
@@ -185,6 +190,7 @@ public class AnnotationConfigReactiveWebServerApplicationContext
...
@@ -185,6 +190,7 @@ public class AnnotationConfigReactiveWebServerApplicationContext
* @see #register(Class...)
* @see #register(Class...)
* @see #refresh()
* @see #refresh()
*/
*/
@Override
public
final
void
scan
(
String
...
basePackages
)
{
public
final
void
scan
(
String
...
basePackages
)
{
Assert
.
notEmpty
(
basePackages
,
"At least one base package must be specified"
);
Assert
.
notEmpty
(
basePackages
,
"At least one base package must be specified"
);
this
.
basePackages
=
basePackages
;
this
.
basePackages
=
basePackages
;
...
@@ -202,8 +208,9 @@ public class AnnotationConfigReactiveWebServerApplicationContext
...
@@ -202,8 +208,9 @@ public class AnnotationConfigReactiveWebServerApplicationContext
if
(!
ObjectUtils
.
isEmpty
(
this
.
basePackages
))
{
if
(!
ObjectUtils
.
isEmpty
(
this
.
basePackages
))
{
this
.
scanner
.
scan
(
this
.
basePackages
);
this
.
scanner
.
scan
(
this
.
basePackages
);
}
}
if
(!
ObjectUtils
.
isEmpty
(
this
.
annotatedClasses
))
{
if
(!
this
.
annotatedClasses
.
isEmpty
())
{
this
.
reader
.
register
(
this
.
annotatedClasses
);
this
.
reader
.
register
(
this
.
annotatedClasses
.
toArray
(
new
Class
<?>[
this
.
annotatedClasses
.
size
()]));
}
}
}
}
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/context/AnnotationConfigServletWebServerApplicationContext.java
View file @
2b9006b3
...
@@ -16,6 +16,10 @@
...
@@ -16,6 +16,10 @@
package
org
.
springframework
.
boot
.
web
.
servlet
.
context
;
package
org
.
springframework
.
boot
.
web
.
servlet
.
context
;
import
java.util.Arrays
;
import
java.util.LinkedHashSet
;
import
java.util.Set
;
import
org.springframework.beans.factory.config.ConfigurableListableBeanFactory
;
import
org.springframework.beans.factory.config.ConfigurableListableBeanFactory
;
import
org.springframework.beans.factory.support.BeanNameGenerator
;
import
org.springframework.beans.factory.support.BeanNameGenerator
;
import
org.springframework.beans.factory.support.DefaultListableBeanFactory
;
import
org.springframework.beans.factory.support.DefaultListableBeanFactory
;
...
@@ -55,7 +59,7 @@ public class AnnotationConfigServletWebServerApplicationContext
...
@@ -55,7 +59,7 @@ public class AnnotationConfigServletWebServerApplicationContext
private
final
ClassPathBeanDefinitionScanner
scanner
;
private
final
ClassPathBeanDefinitionScanner
scanner
;
private
Class
<?>[]
annotatedClasses
;
private
final
Set
<
Class
<?>>
annotatedClasses
=
new
LinkedHashSet
<>()
;
private
String
[]
basePackages
;
private
String
[]
basePackages
;
...
@@ -173,7 +177,7 @@ public class AnnotationConfigServletWebServerApplicationContext
...
@@ -173,7 +177,7 @@ public class AnnotationConfigServletWebServerApplicationContext
public
final
void
register
(
Class
<?>...
annotatedClasses
)
{
public
final
void
register
(
Class
<?>...
annotatedClasses
)
{
Assert
.
notEmpty
(
annotatedClasses
,
Assert
.
notEmpty
(
annotatedClasses
,
"At least one annotated class must be specified"
);
"At least one annotated class must be specified"
);
this
.
annotatedClasses
=
annotatedClasses
;
this
.
annotatedClasses
.
addAll
(
Arrays
.
asList
(
annotatedClasses
))
;
}
}
/**
/**
...
@@ -201,8 +205,9 @@ public class AnnotationConfigServletWebServerApplicationContext
...
@@ -201,8 +205,9 @@ public class AnnotationConfigServletWebServerApplicationContext
if
(
this
.
basePackages
!=
null
&&
this
.
basePackages
.
length
>
0
)
{
if
(
this
.
basePackages
!=
null
&&
this
.
basePackages
.
length
>
0
)
{
this
.
scanner
.
scan
(
this
.
basePackages
);
this
.
scanner
.
scan
(
this
.
basePackages
);
}
}
if
(
this
.
annotatedClasses
!=
null
&&
this
.
annotatedClasses
.
length
>
0
)
{
if
(!
this
.
annotatedClasses
.
isEmpty
())
{
this
.
reader
.
register
(
this
.
annotatedClasses
);
this
.
reader
.
register
(
this
.
annotatedClasses
.
toArray
(
new
Class
<?>[
this
.
annotatedClasses
.
size
()]));
}
}
}
}
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/context/AnnotationConfigReactiveWebServerApplicationContextTests.java
View file @
2b9006b3
/*
/*
* 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");
* 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.
...
@@ -26,6 +26,7 @@ import org.springframework.context.annotation.Configuration;
...
@@ -26,6 +26,7 @@ import org.springframework.context.annotation.Configuration;
import
org.springframework.http.server.reactive.HttpHandler
;
import
org.springframework.http.server.reactive.HttpHandler
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
mock
;
/**
/**
* Tests for {@link AnnotationConfigReactiveWebServerApplicationContext}.
* Tests for {@link AnnotationConfigReactiveWebServerApplicationContext}.
...
@@ -59,6 +60,17 @@ public class AnnotationConfigReactiveWebServerApplicationContextTests {
...
@@ -59,6 +60,17 @@ public class AnnotationConfigReactiveWebServerApplicationContextTests {
verifyContext
();
verifyContext
();
}
}
@Test
public
void
multipleRegistersAndRefresh
()
{
this
.
context
=
new
AnnotationConfigReactiveWebServerApplicationContext
();
this
.
context
.
register
(
WebServerConfiguration
.
class
);
this
.
context
.
register
(
HttpHandlerConfiguration
.
class
);
this
.
context
.
refresh
();
assertThat
(
this
.
context
.
getBeansOfType
(
WebServerConfiguration
.
class
)).
hasSize
(
1
);
assertThat
(
this
.
context
.
getBeansOfType
(
HttpHandlerConfiguration
.
class
))
.
hasSize
(
1
);
}
@Test
@Test
public
void
scanAndRefresh
()
{
public
void
scanAndRefresh
()
{
this
.
context
=
new
AnnotationConfigReactiveWebServerApplicationContext
();
this
.
context
=
new
AnnotationConfigReactiveWebServerApplicationContext
();
...
@@ -85,4 +97,14 @@ public class AnnotationConfigReactiveWebServerApplicationContextTests {
...
@@ -85,4 +97,14 @@ public class AnnotationConfigReactiveWebServerApplicationContextTests {
}
}
@Configuration
public
static
class
HttpHandlerConfiguration
{
@Bean
public
HttpHandler
httpHandler
()
{
return
mock
(
HttpHandler
.
class
);
}
}
}
}
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/AnnotationConfigServletWebServerApplicationContextTests.java
View file @
2b9006b3
/*
/*
* 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");
* 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.
...
@@ -89,6 +89,16 @@ public class AnnotationConfigServletWebServerApplicationContextTests {
...
@@ -89,6 +89,16 @@ public class AnnotationConfigServletWebServerApplicationContextTests {
verifyContext
();
verifyContext
();
}
}
@Test
public
void
multipleRegistersAndRefresh
()
{
this
.
context
=
new
AnnotationConfigServletWebServerApplicationContext
();
this
.
context
.
register
(
WebServerConfiguration
.
class
);
this
.
context
.
register
(
ServletContextAwareConfiguration
.
class
);
this
.
context
.
refresh
();
assertThat
(
this
.
context
.
getBeansOfType
(
Servlet
.
class
)).
hasSize
(
1
);
assertThat
(
this
.
context
.
getBeansOfType
(
ServletWebServerFactory
.
class
)).
hasSize
(
1
);
}
@Test
@Test
public
void
scanAndRefresh
()
{
public
void
scanAndRefresh
()
{
this
.
context
=
new
AnnotationConfigServletWebServerApplicationContext
();
this
.
context
=
new
AnnotationConfigServletWebServerApplicationContext
();
...
...
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