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
5c7a4523
Commit
5c7a4523
authored
Oct 05, 2018
by
Phillip Webb
Browse files
Options
Browse Files
Download
Plain Diff
Merge '2.0.x'
parents
80d27f71
6aedb694
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
67 additions
and
63 deletions
+67
-63
AutoConfigureTestDatabaseWithMultipleDatasourcesIntegrationTests.java
...eTestDatabaseWithMultipleDatasourcesIntegrationTests.java
+1
-1
ExampleJdbcApplication.java
.../boot/test/autoconfigure/jdbc/ExampleJdbcApplication.java
+1
-1
JdbcTestWithAutoConfigureTestDatabaseReplaceExplicitIntegrationTests.java
...ConfigureTestDatabaseReplaceExplicitIntegrationTests.java
+1
-1
JdbcTestWithAutoConfigureTestDatabaseReplacePropertyAnyIntegrationTests.java
...figureTestDatabaseReplacePropertyAnyIntegrationTests.java
+1
-1
ExampleJooqApplication.java
.../boot/test/autoconfigure/jooq/ExampleJooqApplication.java
+1
-1
ExampleDataJpaApplication.java
...test/autoconfigure/orm/jpa/ExampleDataJpaApplication.java
+1
-1
SpringApplication.java
...main/java/org/springframework/boot/SpringApplication.java
+8
-55
WebApplicationType.java
...ain/java/org/springframework/boot/WebApplicationType.java
+53
-2
No files found.
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/AutoConfigureTestDatabaseWithMultipleDatasourcesIntegrationTests.java
View file @
5c7a4523
/*
/*
* 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.
...
...
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/ExampleJdbcApplication.java
View file @
5c7a4523
/*
/*
* 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.
...
...
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplaceExplicitIntegrationTests.java
View file @
5c7a4523
/*
/*
* 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.
...
...
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplacePropertyAnyIntegrationTests.java
View file @
5c7a4523
/*
/*
* 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.
...
...
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jooq/ExampleJooqApplication.java
View file @
5c7a4523
/*
/*
* 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.
...
...
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/orm/jpa/ExampleDataJpaApplication.java
View file @
5c7a4523
/*
/*
* 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.
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java
View file @
5c7a4523
...
@@ -167,12 +167,9 @@ public class SpringApplication {
...
@@ -167,12 +167,9 @@ public class SpringApplication {
* The class name of application context that will be used by default for web
* The class name of application context that will be used by default for web
* environments.
* environments.
*/
*/
public
static
final
String
DEFAULT_WEB_CONTEXT_CLASS
=
"org.springframework.boot."
public
static
final
String
DEFAULT_
SERVLET_
WEB_CONTEXT_CLASS
=
"org.springframework.boot."
+
"web.servlet.context.AnnotationConfigServletWebServerApplicationContext"
;
+
"web.servlet.context.AnnotationConfigServletWebServerApplicationContext"
;
private
static
final
String
[]
WEB_ENVIRONMENT_CLASSES
=
{
"javax.servlet.Servlet"
,
"org.springframework.web.context.ConfigurableWebApplicationContext"
};
/**
/**
* The class name of application context that will be used by default for reactive web
* The class name of application context that will be used by default for reactive web
* environments.
* environments.
...
@@ -180,14 +177,6 @@ public class SpringApplication {
...
@@ -180,14 +177,6 @@ public class SpringApplication {
public
static
final
String
DEFAULT_REACTIVE_WEB_CONTEXT_CLASS
=
"org.springframework."
public
static
final
String
DEFAULT_REACTIVE_WEB_CONTEXT_CLASS
=
"org.springframework."
+
"boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext"
;
+
"boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext"
;
private
static
final
String
REACTIVE_WEB_ENVIRONMENT_CLASS
=
"org.springframework."
+
"web.reactive.DispatcherHandler"
;
private
static
final
String
MVC_WEB_ENVIRONMENT_CLASS
=
"org.springframework."
+
"web.servlet.DispatcherServlet"
;
private
static
final
String
JERSEY_WEB_ENVIRONMENT_CLASS
=
"org.glassfish.jersey.server.ResourceConfig"
;
/**
/**
* Default banner location.
* Default banner location.
*/
*/
...
@@ -273,27 +262,13 @@ public class SpringApplication {
...
@@ -273,27 +262,13 @@ public class SpringApplication {
this
.
resourceLoader
=
resourceLoader
;
this
.
resourceLoader
=
resourceLoader
;
Assert
.
notNull
(
primarySources
,
"PrimarySources must not be null"
);
Assert
.
notNull
(
primarySources
,
"PrimarySources must not be null"
);
this
.
primarySources
=
new
LinkedHashSet
<>(
Arrays
.
asList
(
primarySources
));
this
.
primarySources
=
new
LinkedHashSet
<>(
Arrays
.
asList
(
primarySources
));
this
.
webApplicationType
=
deduceWebApplicationType
();
this
.
webApplicationType
=
WebApplicationType
.
deduceFromClasspath
();
setInitializers
((
Collection
)
getSpringFactoriesInstances
(
setInitializers
((
Collection
)
getSpringFactoriesInstances
(
ApplicationContextInitializer
.
class
));
ApplicationContextInitializer
.
class
));
setListeners
((
Collection
)
getSpringFactoriesInstances
(
ApplicationListener
.
class
));
setListeners
((
Collection
)
getSpringFactoriesInstances
(
ApplicationListener
.
class
));
this
.
mainApplicationClass
=
deduceMainApplicationClass
();
this
.
mainApplicationClass
=
deduceMainApplicationClass
();
}
}
private
WebApplicationType
deduceWebApplicationType
()
{
if
(
ClassUtils
.
isPresent
(
REACTIVE_WEB_ENVIRONMENT_CLASS
,
null
)
&&
!
ClassUtils
.
isPresent
(
MVC_WEB_ENVIRONMENT_CLASS
,
null
)
&&
!
ClassUtils
.
isPresent
(
JERSEY_WEB_ENVIRONMENT_CLASS
,
null
))
{
return
WebApplicationType
.
REACTIVE
;
}
for
(
String
className
:
WEB_ENVIRONMENT_CLASSES
)
{
if
(!
ClassUtils
.
isPresent
(
className
,
null
))
{
return
WebApplicationType
.
NONE
;
}
}
return
WebApplicationType
.
SERVLET
;
}
private
Class
<?>
deduceMainApplicationClass
()
{
private
Class
<?>
deduceMainApplicationClass
()
{
try
{
try
{
StackTraceElement
[]
stackTrace
=
new
RuntimeException
().
getStackTrace
();
StackTraceElement
[]
stackTrace
=
new
RuntimeException
().
getStackTrace
();
...
@@ -609,7 +584,7 @@ public class SpringApplication {
...
@@ -609,7 +584,7 @@ public class SpringApplication {
try
{
try
{
switch
(
this
.
webApplicationType
)
{
switch
(
this
.
webApplicationType
)
{
case
SERVLET:
case
SERVLET:
contextClass
=
Class
.
forName
(
DEFAULT_WEB_CONTEXT_CLASS
);
contextClass
=
Class
.
forName
(
DEFAULT_
SERVLET_
WEB_CONTEXT_CLASS
);
break
;
break
;
case
REACTIVE:
case
REACTIVE:
contextClass
=
Class
.
forName
(
DEFAULT_REACTIVE_WEB_CONTEXT_CLASS
);
contextClass
=
Class
.
forName
(
DEFAULT_REACTIVE_WEB_CONTEXT_CLASS
);
...
@@ -1187,38 +1162,16 @@ public class SpringApplication {
...
@@ -1187,38 +1162,16 @@ public class SpringApplication {
/**
/**
* Sets the type of Spring {@link ApplicationContext} that will be created. If not
* Sets the type of Spring {@link ApplicationContext} that will be created. If not
* specified defaults to {@link #DEFAULT_WEB_CONTEXT_CLASS} for web based applications
* specified defaults to {@link #DEFAULT_SERVLET_WEB_CONTEXT_CLASS} for web based
* or {@link AnnotationConfigApplicationContext} for non web based applications.
* applications or {@link AnnotationConfigApplicationContext} for non web based
* applications.
* @param applicationContextClass the context class to set
* @param applicationContextClass the context class to set
*/
*/
public
void
setApplicationContextClass
(
public
void
setApplicationContextClass
(
Class
<?
extends
ConfigurableApplicationContext
>
applicationContextClass
)
{
Class
<?
extends
ConfigurableApplicationContext
>
applicationContextClass
)
{
this
.
applicationContextClass
=
applicationContextClass
;
this
.
applicationContextClass
=
applicationContextClass
;
this
.
webApplicationType
=
deduceWebApplicationType
(
applicationContextClass
);
this
.
webApplicationType
=
WebApplicationType
}
.
deduceFromApplicationContext
(
applicationContextClass
);
private
WebApplicationType
deduceWebApplicationType
(
Class
<?>
applicationContextClass
)
{
if
(
safeIsAssignableFrom
(
"org.springframework.web.context.WebApplicationContext"
,
applicationContextClass
))
{
return
WebApplicationType
.
SERVLET
;
}
if
(
safeIsAssignableFrom
(
"org.springframework.boot.web.reactive.context.ReactiveWebApplicationContext"
,
applicationContextClass
))
{
return
WebApplicationType
.
REACTIVE
;
}
return
WebApplicationType
.
NONE
;
}
private
boolean
safeIsAssignableFrom
(
String
target
,
Class
<?>
type
)
{
try
{
Class
<?>
targetClass
=
ClassUtils
.
forName
(
target
,
getClassLoader
());
return
targetClass
.
isAssignableFrom
(
type
);
}
catch
(
Throwable
ex
)
{
return
false
;
}
}
}
/**
/**
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/WebApplicationType.java
View file @
5c7a4523
/*
/*
* 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.
...
@@ -16,6 +16,8 @@
...
@@ -16,6 +16,8 @@
package
org
.
springframework
.
boot
;
package
org
.
springframework
.
boot
;
import
org.springframework.util.ClassUtils
;
/**
/**
* An enumeration of possible types of web application.
* An enumeration of possible types of web application.
*
*
...
@@ -41,6 +43,55 @@ public enum WebApplicationType {
...
@@ -41,6 +43,55 @@ public enum WebApplicationType {
* The application should run as a reactive web application and should start an
* The application should run as a reactive web application and should start an
* embedded reactive web server.
* embedded reactive web server.
*/
*/
REACTIVE
REACTIVE
;
private
static
final
String
[]
SERVLET_INDICATOR_CLASSES
=
{
"javax.servlet.Servlet"
,
"org.springframework.web.context.ConfigurableWebApplicationContext"
};
private
static
final
String
WEBMVC_INDICATOR_CLASS
=
"org.springframework."
+
"web.servlet.DispatcherServlet"
;
private
static
final
String
WEBFLUX_INDICATOR_CLASS
=
"org."
+
"springframework.web.reactive.DispatcherHandler"
;
private
static
final
String
JERSEY_INDICATOR_CLASS
=
"org.glassfish.jersey.server.ResourceConfig"
;
private
static
final
String
SERVLET_APPLICATION_CONTEXT_CLASS
=
"org.springframework.web.context.WebApplicationContext"
;
private
static
final
String
REACTIVE_APPLICATION_CONTEXT_CLASS
=
"org.springframework.boot.web.reactive.context.ReactiveWebApplicationContext"
;
static
WebApplicationType
deduceFromClasspath
()
{
if
(
ClassUtils
.
isPresent
(
WEBFLUX_INDICATOR_CLASS
,
null
)
&&
!
ClassUtils
.
isPresent
(
WEBMVC_INDICATOR_CLASS
,
null
)
&&
!
ClassUtils
.
isPresent
(
JERSEY_INDICATOR_CLASS
,
null
))
{
return
WebApplicationType
.
REACTIVE
;
}
for
(
String
className
:
SERVLET_INDICATOR_CLASSES
)
{
if
(!
ClassUtils
.
isPresent
(
className
,
null
))
{
return
WebApplicationType
.
NONE
;
}
}
return
WebApplicationType
.
SERVLET
;
}
static
WebApplicationType
deduceFromApplicationContext
(
Class
<?>
applicationContextClass
)
{
if
(
isAssignable
(
SERVLET_APPLICATION_CONTEXT_CLASS
,
applicationContextClass
))
{
return
WebApplicationType
.
SERVLET
;
}
if
(
isAssignable
(
REACTIVE_APPLICATION_CONTEXT_CLASS
,
applicationContextClass
))
{
return
WebApplicationType
.
REACTIVE
;
}
return
WebApplicationType
.
NONE
;
}
private
static
boolean
isAssignable
(
String
target
,
Class
<?>
type
)
{
try
{
return
ClassUtils
.
resolveClassName
(
target
,
null
).
isAssignableFrom
(
type
);
}
catch
(
Throwable
ex
)
{
return
false
;
}
}
}
}
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