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
b4c5aea1
Commit
b4c5aea1
authored
Oct 03, 2018
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix detection of WebApplicationType with context class
Closes gh-14589
parent
73e6a39b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
8 deletions
+38
-8
SpringApplication.java
...main/java/org/springframework/boot/SpringApplication.java
+10
-8
SpringApplicationTests.java
...java/org/springframework/boot/SpringApplicationTests.java
+28
-0
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java
View file @
b4c5aea1
...
...
@@ -43,6 +43,7 @@ import org.springframework.boot.Banner.Mode;
import
org.springframework.boot.context.properties.bind.Bindable
;
import
org.springframework.boot.context.properties.bind.Binder
;
import
org.springframework.boot.context.properties.source.ConfigurationPropertySources
;
import
org.springframework.boot.web.reactive.context.ReactiveWebApplicationContext
;
import
org.springframework.boot.web.reactive.context.StandardReactiveWebEnvironment
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContextInitializer
;
...
...
@@ -1181,18 +1182,19 @@ public class SpringApplication {
public
void
setApplicationContextClass
(
Class
<?
extends
ConfigurableApplicationContext
>
applicationContextClass
)
{
this
.
applicationContextClass
=
applicationContextClass
;
if
(!
isWebApplicationContext
(
applicationContextClass
))
{
this
.
webApplicationType
=
WebApplicationType
.
NONE
;
}
this
.
webApplicationType
=
deduceWebApplicationType
(
applicationContextClass
);
}
private
boolean
isWebApplicationContext
(
Class
<?>
applicationContextClass
)
{
try
{
return
WebApplicationContext
.
class
.
isAssignableFrom
(
applicationContextClass
);
private
WebApplicationType
deduceWebApplicationType
(
Class
<?>
applicationContextClass
)
{
if
(
WebApplicationContext
.
class
.
isAssignableFrom
(
applicationContextClass
))
{
return
WebApplicationType
.
SERVLET
;
}
catch
(
NoClassDefFoundError
ex
)
{
return
false
;
if
(
ReactiveWebApplicationContext
.
class
.
isAssignableFrom
(
applicationContextClass
))
{
return
WebApplicationType
.
REACTIVE
;
}
return
WebApplicationType
.
NONE
;
}
/**
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java
View file @
b4c5aea1
...
...
@@ -58,6 +58,7 @@ import org.springframework.boot.context.event.SpringApplicationEvent;
import
org.springframework.boot.testsupport.rule.OutputCapture
;
import
org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory
;
import
org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory
;
import
org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebApplicationContext
;
import
org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext
;
import
org.springframework.boot.web.reactive.context.ReactiveWebApplicationContext
;
import
org.springframework.boot.web.reactive.context.StandardReactiveWebEnvironment
;
...
...
@@ -96,6 +97,7 @@ import org.springframework.util.ReflectionUtils;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.context.ConfigurableWebEnvironment
;
import
org.springframework.web.context.WebApplicationContext
;
import
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
;
import
org.springframework.web.context.support.StandardServletEnvironment
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
...
@@ -316,6 +318,32 @@ public class SpringApplicationTests {
assertThat
(
this
.
context
).
isInstanceOf
(
StaticApplicationContext
.
class
);
}
@Test
public
void
specificWebApplicationContextClassDetectWebApplicationType
()
{
SpringApplication
application
=
new
SpringApplication
(
ExampleConfig
.
class
);
application
.
setApplicationContextClass
(
AnnotationConfigWebApplicationContext
.
class
);
assertThat
(
application
.
getWebApplicationType
())
.
isEqualTo
(
WebApplicationType
.
SERVLET
);
}
@Test
public
void
specificReactiveApplicationContextClassDetectReactiveApplicationType
()
{
SpringApplication
application
=
new
SpringApplication
(
ExampleConfig
.
class
);
application
.
setApplicationContextClass
(
AnnotationConfigReactiveWebApplicationContext
.
class
);
assertThat
(
application
.
getWebApplicationType
())
.
isEqualTo
(
WebApplicationType
.
REACTIVE
);
}
@Test
public
void
nonWebNorReactiveApplicationContextClassDetectNoneApplicationType
()
{
SpringApplication
application
=
new
SpringApplication
(
ExampleConfig
.
class
);
application
.
setApplicationContextClass
(
StaticApplicationContext
.
class
);
assertThat
(
application
.
getWebApplicationType
())
.
isEqualTo
(
WebApplicationType
.
NONE
);
}
@Test
public
void
specificApplicationContextInitializer
()
{
SpringApplication
application
=
new
SpringApplication
(
ExampleConfig
.
class
);
...
...
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