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
3331fa2d
Commit
3331fa2d
authored
Nov 23, 2018
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.5.x' into 2.0.x
parents
a54de61e
291522a2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
5 deletions
+41
-5
ServletWebServerApplicationContext.java
...b/servlet/context/ServletWebServerApplicationContext.java
+12
-5
ServletWebServerApplicationContextTests.java
...vlet/context/ServletWebServerApplicationContextTests.java
+29
-0
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/context/ServletWebServerApplicationContext.java
View file @
3331fa2d
...
...
@@ -55,6 +55,7 @@ import org.springframework.web.context.WebApplicationContext;
import
org.springframework.web.context.support.GenericWebApplicationContext
;
import
org.springframework.web.context.support.ServletContextAwareProcessor
;
import
org.springframework.web.context.support.ServletContextResource
;
import
org.springframework.web.context.support.ServletContextScope
;
import
org.springframework.web.context.support.WebApplicationContextUtils
;
/**
...
...
@@ -132,7 +133,7 @@ public class ServletWebServerApplicationContext extends GenericWebApplicationCon
beanFactory
.
addBeanPostProcessor
(
new
WebApplicationContextServletContextAwareProcessor
(
this
));
beanFactory
.
ignoreDependencyInterface
(
ServletContextAware
.
class
);
registerWebApplicationScopes
(
null
);
registerWebApplicationScopes
();
}
@Override
...
...
@@ -227,7 +228,7 @@ public class ServletWebServerApplicationContext extends GenericWebApplicationCon
private
void
selfInitialize
(
ServletContext
servletContext
)
throws
ServletException
{
prepareWebApplicationContext
(
servletContext
);
register
WebApplicationScopes
(
servletContext
);
register
ApplicationScope
(
servletContext
);
WebApplicationContextUtils
.
registerEnvironmentBeans
(
getBeanFactory
(),
servletContext
);
for
(
ServletContextInitializer
beans
:
getServletContextInitializerBeans
())
{
...
...
@@ -235,11 +236,17 @@ public class ServletWebServerApplicationContext extends GenericWebApplicationCon
}
}
private
void
registerWebApplicationScopes
(
ServletContext
servletContext
)
{
private
void
registerApplicationScope
(
ServletContext
servletContext
)
{
ServletContextScope
appScope
=
new
ServletContextScope
(
servletContext
);
getBeanFactory
().
registerScope
(
WebApplicationContext
.
SCOPE_APPLICATION
,
appScope
);
// Register as ServletContext attribute, for ContextCleanupListener to detect it.
servletContext
.
setAttribute
(
ServletContextScope
.
class
.
getName
(),
appScope
);
}
private
void
registerWebApplicationScopes
()
{
ExistingWebApplicationScopes
existingScopes
=
new
ExistingWebApplicationScopes
(
getBeanFactory
());
WebApplicationContextUtils
.
registerWebApplicationScopes
(
getBeanFactory
(),
servletContext
);
WebApplicationContextUtils
.
registerWebApplicationScopes
(
getBeanFactory
());
existingScopes
.
restore
();
}
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/ServletWebServerApplicationContextTests.java
View file @
3331fa2d
...
...
@@ -49,6 +49,7 @@ import org.springframework.beans.factory.config.ConstructorArgumentValues;
import
org.springframework.beans.factory.config.Scope
;
import
org.springframework.beans.factory.support.AbstractBeanDefinition
;
import
org.springframework.beans.factory.support.RootBeanDefinition
;
import
org.springframework.boot.testsupport.rule.OutputCapture
;
import
org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer
;
import
org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean
;
import
org.springframework.boot.web.servlet.FilterRegistrationBean
;
...
...
@@ -94,6 +95,9 @@ public class ServletWebServerApplicationContextTests {
private
ServletWebServerApplicationContext
context
;
@Rule
public
OutputCapture
output
=
new
OutputCapture
();
@Captor
private
ArgumentCaptor
<
Filter
>
filterCaptor
;
...
...
@@ -469,6 +473,7 @@ public class ServletWebServerApplicationContextTests {
@Test
public
void
servletRequestCanBeInjectedEarly
()
throws
Exception
{
// gh-14990
int
initialOutputLength
=
this
.
output
.
toString
().
length
();
addWebServerFactoryBean
();
RootBeanDefinition
beanDefinition
=
new
RootBeanDefinition
(
WithAutowiredServletRequest
.
class
);
...
...
@@ -487,6 +492,16 @@ public class ServletWebServerApplicationContextTests {
});
this
.
context
.
refresh
();
String
output
=
this
.
output
.
toString
().
substring
(
initialOutputLength
);
assertThat
(
output
).
doesNotContain
(
"Replacing scope"
);
}
@Test
public
void
webApplicationScopeIsRegistered
()
throws
Exception
{
addWebServerFactoryBean
();
this
.
context
.
refresh
();
assertThat
(
this
.
context
.
getBeanFactory
()
.
getRegisteredScope
(
WebApplicationContext
.
SCOPE_APPLICATION
)).
isNotNull
();
}
private
void
addWebServerFactoryBean
()
{
...
...
@@ -555,4 +570,18 @@ public class ServletWebServerApplicationContextTests {
}
protected
static
class
WithAutowiredServletContext
{
private
final
ServletContext
context
;
public
WithAutowiredServletContext
(
ServletContext
context
)
{
this
.
context
=
context
;
}
public
ServletContext
getContext
()
{
return
this
.
context
;
}
}
}
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