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
95f659f4
Commit
95f659f4
authored
Jan 24, 2017
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new WebApplicationType enum to pave the way for Web Flux support
Closes gh-8077
parent
4e3d606f
Changes
24
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
24 changed files
with
259 additions
and
152 deletions
+259
-152
ShutdownParentEndpointTests.java
...rk/boot/actuate/endpoint/ShutdownParentEndpointTests.java
+4
-3
SpringApplicationAdminJmxAutoConfigurationTests.java
...dmin/SpringApplicationAdminJmxAutoConfigurationTests.java
+5
-4
ResourceServerTokenServicesConfigurationTests.java
...source/ResourceServerTokenServicesConfigurationTests.java
+14
-12
RemoteSpringApplication.java
...pringframework/boot/devtools/RemoteSpringApplication.java
+3
-2
RemoteUrlPropertyExtractorTests.java
...mework/boot/devtools/RemoteUrlPropertyExtractorTests.java
+3
-2
DevToolPropertiesIntegrationTests.java
.../boot/devtools/env/DevToolPropertiesIntegrationTests.java
+6
-5
RestartScopeInitializerTests.java
...k/boot/devtools/restart/RestartScopeInitializerTests.java
+3
-2
SampleJersey1Application.java
...rc/main/java/sample/jersey1/SampleJersey1Application.java
+4
-2
SpringBootDependencyInjectionTestExecutionListenerTests.java
...ingBootDependencyInjectionTestExecutionListenerTests.java
+3
-2
SpringBootContextLoader.java
...gframework/boot/test/context/SpringBootContextLoader.java
+3
-2
SpringApplication.java
...main/java/org/springframework/boot/SpringApplication.java
+42
-13
WebApplicationType.java
...ain/java/org/springframework/boot/WebApplicationType.java
+39
-0
SpringApplicationBuilder.java
...pringframework/boot/builder/SpringApplicationBuilder.java
+16
-1
BannerTests.java
...t/src/test/java/org/springframework/boot/BannerTests.java
+7
-7
ReproTests.java
...ot/src/test/java/org/springframework/boot/ReproTests.java
+13
-13
SpringApplicationTests.java
...java/org/springframework/boot/SpringApplicationTests.java
+43
-42
SpringApplicationAdminMXBeanRegistrarTests.java
...oot/admin/SpringApplicationAdminMXBeanRegistrarTests.java
+5
-4
SpringApplicationBindContextLoader.java
...amework/boot/bind/SpringApplicationBindContextLoader.java
+3
-2
SpringApplicationBuilderTests.java
...framework/boot/builder/SpringApplicationBuilderTests.java
+11
-8
AnsiOutputApplicationListenerTests.java
...ot/context/config/AnsiOutputApplicationListenerTests.java
+5
-4
ConfigFileApplicationListenerTests.java
...ot/context/config/ConfigFileApplicationListenerTests.java
+15
-14
FailureAnalyzersIntegrationTests.java
...rk/boot/diagnostics/FailureAnalyzersIntegrationTests.java
+4
-2
LiquibaseServiceLocatorApplicationListenerTests.java
...base/LiquibaseServiceLocatorApplicationListenerTests.java
+3
-2
LoggingApplicationListenerIntegrationTests.java
...t/logging/LoggingApplicationListenerIntegrationTests.java
+5
-4
No files found.
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ShutdownParentEndpointTests.java
View file @
95f659f4
/*
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
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.
...
@@ -22,6 +22,7 @@ import java.util.concurrent.TimeUnit;
...
@@ -22,6 +22,7 @@ import java.util.concurrent.TimeUnit;
import
org.junit.After
;
import
org.junit.After
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.springframework.boot.WebApplicationType
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.test.util.ApplicationContextTestUtils
;
import
org.springframework.boot.test.util.ApplicationContextTestUtils
;
...
@@ -50,7 +51,7 @@ public class ShutdownParentEndpointTests {
...
@@ -50,7 +51,7 @@ public class ShutdownParentEndpointTests {
@Test
@Test
public
void
shutdownChild
()
throws
Exception
{
public
void
shutdownChild
()
throws
Exception
{
this
.
context
=
new
SpringApplicationBuilder
(
Config
.
class
).
child
(
Empty
.
class
)
this
.
context
=
new
SpringApplicationBuilder
(
Config
.
class
).
child
(
Empty
.
class
)
.
web
(
false
).
run
();
.
web
(
WebApplicationType
.
NONE
).
run
();
CountDownLatch
latch
=
this
.
context
.
getBean
(
Config
.
class
).
latch
;
CountDownLatch
latch
=
this
.
context
.
getBean
(
Config
.
class
).
latch
;
assertThat
((
String
)
getEndpointBean
().
invoke
().
get
(
"message"
))
assertThat
((
String
)
getEndpointBean
().
invoke
().
get
(
"message"
))
.
startsWith
(
"Shutting down"
);
.
startsWith
(
"Shutting down"
);
...
@@ -61,7 +62,7 @@ public class ShutdownParentEndpointTests {
...
@@ -61,7 +62,7 @@ public class ShutdownParentEndpointTests {
@Test
@Test
public
void
shutdownParent
()
throws
Exception
{
public
void
shutdownParent
()
throws
Exception
{
this
.
context
=
new
SpringApplicationBuilder
(
Empty
.
class
).
child
(
Config
.
class
)
this
.
context
=
new
SpringApplicationBuilder
(
Empty
.
class
).
child
(
Config
.
class
)
.
web
(
false
).
run
();
.
web
(
WebApplicationType
.
NONE
).
run
();
CountDownLatch
latch
=
this
.
context
.
getBean
(
Config
.
class
).
latch
;
CountDownLatch
latch
=
this
.
context
.
getBean
(
Config
.
class
).
latch
;
assertThat
((
String
)
getEndpointBean
().
invoke
().
get
(
"message"
))
assertThat
((
String
)
getEndpointBean
().
invoke
().
get
(
"message"
))
.
startsWith
(
"Shutting down"
);
.
startsWith
(
"Shutting down"
);
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/admin/SpringApplicationAdminJmxAutoConfigurationTests.java
View file @
95f659f4
/*
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
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.
...
@@ -32,6 +32,7 @@ import org.junit.rules.ExpectedException;
...
@@ -32,6 +32,7 @@ import org.junit.rules.ExpectedException;
import
org.springframework.beans.factory.BeanFactoryUtils
;
import
org.springframework.beans.factory.BeanFactoryUtils
;
import
org.springframework.beans.factory.NoSuchBeanDefinitionException
;
import
org.springframework.beans.factory.NoSuchBeanDefinitionException
;
import
org.springframework.boot.WebApplicationType
;
import
org.springframework.boot.admin.SpringApplicationAdminMXBeanRegistrar
;
import
org.springframework.boot.admin.SpringApplicationAdminMXBeanRegistrar
;
import
org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration
;
import
org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration
;
import
org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration
;
import
org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration
;
...
@@ -136,13 +137,13 @@ public class SpringApplicationAdminJmxAutoConfigurationTests {
...
@@ -136,13 +137,13 @@ public class SpringApplicationAdminJmxAutoConfigurationTests {
@Test
@Test
public
void
onlyRegisteredOnceWhenThereIsAChildContext
()
throws
Exception
{
public
void
onlyRegisteredOnceWhenThereIsAChildContext
()
throws
Exception
{
SpringApplicationBuilder
parentBuilder
=
new
SpringApplicationBuilder
()
.
web
(
false
)
SpringApplicationBuilder
parentBuilder
=
new
SpringApplicationBuilder
()
.
sources
(
JmxAutoConfiguration
.
class
,
.
web
(
WebApplicationType
.
NONE
).
sources
(
JmxAutoConfiguration
.
class
,
SpringApplicationAdminJmxAutoConfiguration
.
class
);
SpringApplicationAdminJmxAutoConfiguration
.
class
);
SpringApplicationBuilder
childBuilder
=
parentBuilder
SpringApplicationBuilder
childBuilder
=
parentBuilder
.
child
(
JmxAutoConfiguration
.
class
,
.
child
(
JmxAutoConfiguration
.
class
,
SpringApplicationAdminJmxAutoConfiguration
.
class
)
SpringApplicationAdminJmxAutoConfiguration
.
class
)
.
web
(
false
);
.
web
(
WebApplicationType
.
NONE
);
ConfigurableApplicationContext
parent
=
null
;
ConfigurableApplicationContext
parent
=
null
;
ConfigurableApplicationContext
child
=
null
;
ConfigurableApplicationContext
child
=
null
;
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfigurationTests.java
View file @
95f659f4
...
@@ -25,6 +25,7 @@ import org.junit.Test;
...
@@ -25,6 +25,7 @@ import org.junit.Test;
import
org.springframework.beans.factory.config.BeanDefinition
;
import
org.springframework.beans.factory.config.BeanDefinition
;
import
org.springframework.beans.factory.support.BeanDefinitionRegistry
;
import
org.springframework.beans.factory.support.BeanDefinitionRegistry
;
import
org.springframework.boot.WebApplicationType
;
import
org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.autoconfigure.security.oauth2.OAuth2ClientProperties
;
import
org.springframework.boot.autoconfigure.security.oauth2.OAuth2ClientProperties
;
import
org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2RestOperationsConfiguration
;
import
org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2RestOperationsConfiguration
;
...
@@ -86,7 +87,7 @@ public class ResourceServerTokenServicesConfigurationTests {
...
@@ -86,7 +87,7 @@ public class ResourceServerTokenServicesConfigurationTests {
@Test
@Test
public
void
defaultIsRemoteTokenServices
()
{
public
void
defaultIsRemoteTokenServices
()
{
this
.
context
=
new
SpringApplicationBuilder
(
ResourceConfiguration
.
class
)
this
.
context
=
new
SpringApplicationBuilder
(
ResourceConfiguration
.
class
)
.
web
(
false
).
run
();
.
web
(
WebApplicationType
.
NONE
).
run
();
RemoteTokenServices
services
=
this
.
context
.
getBean
(
RemoteTokenServices
.
class
);
RemoteTokenServices
services
=
this
.
context
.
getBean
(
RemoteTokenServices
.
class
);
assertThat
(
services
).
isNotNull
();
assertThat
(
services
).
isNotNull
();
}
}
...
@@ -97,7 +98,7 @@ public class ResourceServerTokenServicesConfigurationTests {
...
@@ -97,7 +98,7 @@ public class ResourceServerTokenServicesConfigurationTests {
"security.oauth2.resource.tokenInfoUri:http://example.com"
,
"security.oauth2.resource.tokenInfoUri:http://example.com"
,
"security.oauth2.resource.clientId=acme"
);
"security.oauth2.resource.clientId=acme"
);
this
.
context
=
new
SpringApplicationBuilder
(
ResourceConfiguration
.
class
)
this
.
context
=
new
SpringApplicationBuilder
(
ResourceConfiguration
.
class
)
.
environment
(
this
.
environment
).
web
(
false
).
run
();
.
environment
(
this
.
environment
).
web
(
WebApplicationType
.
NONE
).
run
();
RemoteTokenServices
services
=
this
.
context
.
getBean
(
RemoteTokenServices
.
class
);
RemoteTokenServices
services
=
this
.
context
.
getBean
(
RemoteTokenServices
.
class
);
assertThat
(
services
).
isNotNull
();
assertThat
(
services
).
isNotNull
();
}
}
...
@@ -107,7 +108,7 @@ public class ResourceServerTokenServicesConfigurationTests {
...
@@ -107,7 +108,7 @@ public class ResourceServerTokenServicesConfigurationTests {
EnvironmentTestUtils
.
addEnvironment
(
this
.
environment
,
EnvironmentTestUtils
.
addEnvironment
(
this
.
environment
,
"security.oauth2.resource.userInfoUri:http://example.com"
);
"security.oauth2.resource.userInfoUri:http://example.com"
);
this
.
context
=
new
SpringApplicationBuilder
(
ResourceConfiguration
.
class
)
this
.
context
=
new
SpringApplicationBuilder
(
ResourceConfiguration
.
class
)
.
environment
(
this
.
environment
).
web
(
false
).
run
();
.
environment
(
this
.
environment
).
web
(
WebApplicationType
.
NONE
).
run
();
UserInfoTokenServices
services
=
this
.
context
UserInfoTokenServices
services
=
this
.
context
.
getBean
(
UserInfoTokenServices
.
class
);
.
getBean
(
UserInfoTokenServices
.
class
);
assertThat
(
services
).
isNotNull
();
assertThat
(
services
).
isNotNull
();
...
@@ -118,7 +119,7 @@ public class ResourceServerTokenServicesConfigurationTests {
...
@@ -118,7 +119,7 @@ public class ResourceServerTokenServicesConfigurationTests {
EnvironmentTestUtils
.
addEnvironment
(
this
.
environment
,
EnvironmentTestUtils
.
addEnvironment
(
this
.
environment
,
"security.oauth2.resource.userInfoUri:http://example.com"
);
"security.oauth2.resource.userInfoUri:http://example.com"
);
this
.
context
=
new
SpringApplicationBuilder
(
AuthoritiesConfiguration
.
class
)
this
.
context
=
new
SpringApplicationBuilder
(
AuthoritiesConfiguration
.
class
)
.
environment
(
this
.
environment
).
web
(
false
).
run
();
.
environment
(
this
.
environment
).
web
(
WebApplicationType
.
NONE
).
run
();
UserInfoTokenServices
services
=
this
.
context
UserInfoTokenServices
services
=
this
.
context
.
getBean
(
UserInfoTokenServices
.
class
);
.
getBean
(
UserInfoTokenServices
.
class
);
assertThat
(
services
).
isNotNull
();
assertThat
(
services
).
isNotNull
();
...
@@ -131,7 +132,7 @@ public class ResourceServerTokenServicesConfigurationTests {
...
@@ -131,7 +132,7 @@ public class ResourceServerTokenServicesConfigurationTests {
EnvironmentTestUtils
.
addEnvironment
(
this
.
environment
,
EnvironmentTestUtils
.
addEnvironment
(
this
.
environment
,
"security.oauth2.resource.userInfoUri:http://example.com"
);
"security.oauth2.resource.userInfoUri:http://example.com"
);
this
.
context
=
new
SpringApplicationBuilder
(
PrincipalConfiguration
.
class
)
this
.
context
=
new
SpringApplicationBuilder
(
PrincipalConfiguration
.
class
)
.
environment
(
this
.
environment
).
web
(
false
).
run
();
.
environment
(
this
.
environment
).
web
(
WebApplicationType
.
NONE
).
run
();
UserInfoTokenServices
services
=
this
.
context
UserInfoTokenServices
services
=
this
.
context
.
getBean
(
UserInfoTokenServices
.
class
);
.
getBean
(
UserInfoTokenServices
.
class
);
assertThat
(
services
).
isNotNull
();
assertThat
(
services
).
isNotNull
();
...
@@ -146,7 +147,7 @@ public class ResourceServerTokenServicesConfigurationTests {
...
@@ -146,7 +147,7 @@ public class ResourceServerTokenServicesConfigurationTests {
"security.oauth2.resource.userInfoUri:http://example.com"
,
"security.oauth2.resource.userInfoUri:http://example.com"
,
"server.port=-1"
,
"debug=true"
);
"server.port=-1"
,
"debug=true"
);
this
.
context
=
new
SpringApplicationBuilder
(
ResourceNoClientConfiguration
.
class
)
this
.
context
=
new
SpringApplicationBuilder
(
ResourceNoClientConfiguration
.
class
)
.
environment
(
this
.
environment
).
web
(
true
).
run
();
.
environment
(
this
.
environment
).
web
(
WebApplicationType
.
SERVLET
).
run
();
BeanDefinition
bean
=
((
BeanDefinitionRegistry
)
this
.
context
)
BeanDefinition
bean
=
((
BeanDefinitionRegistry
)
this
.
context
)
.
getBeanDefinition
(
"scopedTarget.oauth2ClientContext"
);
.
getBeanDefinition
(
"scopedTarget.oauth2ClientContext"
);
assertThat
(
bean
.
getScope
()).
isEqualTo
(
"request"
);
assertThat
(
bean
.
getScope
()).
isEqualTo
(
"request"
);
...
@@ -159,7 +160,7 @@ public class ResourceServerTokenServicesConfigurationTests {
...
@@ -159,7 +160,7 @@ public class ResourceServerTokenServicesConfigurationTests {
"security.oauth2.resource.tokenInfoUri:http://example.com"
,
"security.oauth2.resource.tokenInfoUri:http://example.com"
,
"security.oauth2.resource.preferTokenInfo:false"
);
"security.oauth2.resource.preferTokenInfo:false"
);
this
.
context
=
new
SpringApplicationBuilder
(
ResourceConfiguration
.
class
)
this
.
context
=
new
SpringApplicationBuilder
(
ResourceConfiguration
.
class
)
.
environment
(
this
.
environment
).
web
(
false
).
run
();
.
environment
(
this
.
environment
).
web
(
WebApplicationType
.
NONE
).
run
();
UserInfoTokenServices
services
=
this
.
context
UserInfoTokenServices
services
=
this
.
context
.
getBean
(
UserInfoTokenServices
.
class
);
.
getBean
(
UserInfoTokenServices
.
class
);
assertThat
(
services
).
isNotNull
();
assertThat
(
services
).
isNotNull
();
...
@@ -172,7 +173,8 @@ public class ResourceServerTokenServicesConfigurationTests {
...
@@ -172,7 +173,8 @@ public class ResourceServerTokenServicesConfigurationTests {
"security.oauth2.resource.tokenInfoUri:http://example.com"
,
"security.oauth2.resource.tokenInfoUri:http://example.com"
,
"security.oauth2.resource.preferTokenInfo:false"
);
"security.oauth2.resource.preferTokenInfo:false"
);
this
.
context
=
new
SpringApplicationBuilder
(
ResourceConfiguration
.
class
,
this
.
context
=
new
SpringApplicationBuilder
(
ResourceConfiguration
.
class
,
Customizer
.
class
).
environment
(
this
.
environment
).
web
(
false
).
run
();
Customizer
.
class
).
environment
(
this
.
environment
).
web
(
WebApplicationType
.
NONE
)
.
run
();
UserInfoTokenServices
services
=
this
.
context
UserInfoTokenServices
services
=
this
.
context
.
getBean
(
UserInfoTokenServices
.
class
);
.
getBean
(
UserInfoTokenServices
.
class
);
assertThat
(
services
).
isNotNull
();
assertThat
(
services
).
isNotNull
();
...
@@ -183,7 +185,7 @@ public class ResourceServerTokenServicesConfigurationTests {
...
@@ -183,7 +185,7 @@ public class ResourceServerTokenServicesConfigurationTests {
EnvironmentTestUtils
.
addEnvironment
(
this
.
environment
,
EnvironmentTestUtils
.
addEnvironment
(
this
.
environment
,
"security.oauth2.resource.jwt.keyValue=FOOBAR"
);
"security.oauth2.resource.jwt.keyValue=FOOBAR"
);
this
.
context
=
new
SpringApplicationBuilder
(
ResourceConfiguration
.
class
)
this
.
context
=
new
SpringApplicationBuilder
(
ResourceConfiguration
.
class
)
.
environment
(
this
.
environment
).
web
(
false
).
run
();
.
environment
(
this
.
environment
).
web
(
WebApplicationType
.
NONE
).
run
();
DefaultTokenServices
services
=
this
.
context
.
getBean
(
DefaultTokenServices
.
class
);
DefaultTokenServices
services
=
this
.
context
.
getBean
(
DefaultTokenServices
.
class
);
assertThat
(
services
).
isNotNull
();
assertThat
(
services
).
isNotNull
();
}
}
...
@@ -193,7 +195,7 @@ public class ResourceServerTokenServicesConfigurationTests {
...
@@ -193,7 +195,7 @@ public class ResourceServerTokenServicesConfigurationTests {
EnvironmentTestUtils
.
addEnvironment
(
this
.
environment
,
EnvironmentTestUtils
.
addEnvironment
(
this
.
environment
,
"security.oauth2.resource.jwt.keyValue="
+
PUBLIC_KEY
);
"security.oauth2.resource.jwt.keyValue="
+
PUBLIC_KEY
);
this
.
context
=
new
SpringApplicationBuilder
(
ResourceConfiguration
.
class
)
this
.
context
=
new
SpringApplicationBuilder
(
ResourceConfiguration
.
class
)
.
environment
(
this
.
environment
).
web
(
false
).
run
();
.
environment
(
this
.
environment
).
web
(
WebApplicationType
.
NONE
).
run
();
DefaultTokenServices
services
=
this
.
context
.
getBean
(
DefaultTokenServices
.
class
);
DefaultTokenServices
services
=
this
.
context
.
getBean
(
DefaultTokenServices
.
class
);
assertThat
(
services
).
isNotNull
();
assertThat
(
services
).
isNotNull
();
}
}
...
@@ -205,7 +207,7 @@ public class ResourceServerTokenServicesConfigurationTests {
...
@@ -205,7 +207,7 @@ public class ResourceServerTokenServicesConfigurationTests {
"spring.social.facebook.app-id=foo"
,
"spring.social.facebook.app-id=foo"
,
"spring.social.facebook.app-secret=bar"
);
"spring.social.facebook.app-secret=bar"
);
this
.
context
=
new
SpringApplicationBuilder
(
SocialResourceConfiguration
.
class
)
this
.
context
=
new
SpringApplicationBuilder
(
SocialResourceConfiguration
.
class
)
.
environment
(
this
.
environment
).
web
(
true
).
run
();
.
environment
(
this
.
environment
).
web
(
WebApplicationType
.
SERVLET
).
run
();
ConnectionFactoryLocator
connectionFactory
=
this
.
context
ConnectionFactoryLocator
connectionFactory
=
this
.
context
.
getBean
(
ConnectionFactoryLocator
.
class
);
.
getBean
(
ConnectionFactoryLocator
.
class
);
assertThat
(
connectionFactory
).
isNotNull
();
assertThat
(
connectionFactory
).
isNotNull
();
...
@@ -220,7 +222,7 @@ public class ResourceServerTokenServicesConfigurationTests {
...
@@ -220,7 +222,7 @@ public class ResourceServerTokenServicesConfigurationTests {
"security.oauth2.resource.userInfoUri:http://example.com"
);
"security.oauth2.resource.userInfoUri:http://example.com"
);
this
.
context
=
new
SpringApplicationBuilder
(
this
.
context
=
new
SpringApplicationBuilder
(
CustomUserInfoRestTemplateFactory
.
class
,
ResourceConfiguration
.
class
)
CustomUserInfoRestTemplateFactory
.
class
,
ResourceConfiguration
.
class
)
.
environment
(
this
.
environment
).
web
(
false
).
run
();
.
environment
(
this
.
environment
).
web
(
WebApplicationType
.
NONE
).
run
();
assertThat
(
this
.
context
.
getBeansOfType
(
UserInfoRestTemplateFactory
.
class
))
assertThat
(
this
.
context
.
getBeansOfType
(
UserInfoRestTemplateFactory
.
class
))
.
hasSize
(
1
);
.
hasSize
(
1
);
assertThat
(
this
.
context
.
getBean
(
UserInfoRestTemplateFactory
.
class
))
assertThat
(
this
.
context
.
getBean
(
UserInfoRestTemplateFactory
.
class
))
...
...
spring-boot-devtools/src/main/java/org/springframework/boot/devtools/RemoteSpringApplication.java
View file @
95f659f4
/*
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
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.
...
@@ -23,6 +23,7 @@ import java.util.List;
...
@@ -23,6 +23,7 @@ import java.util.List;
import
org.springframework.boot.Banner
;
import
org.springframework.boot.Banner
;
import
org.springframework.boot.ResourceBanner
;
import
org.springframework.boot.ResourceBanner
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.WebApplicationType
;
import
org.springframework.boot.context.config.AnsiOutputApplicationListener
;
import
org.springframework.boot.context.config.AnsiOutputApplicationListener
;
import
org.springframework.boot.context.config.ConfigFileApplicationListener
;
import
org.springframework.boot.context.config.ConfigFileApplicationListener
;
import
org.springframework.boot.devtools.remote.client.RemoteClientConfiguration
;
import
org.springframework.boot.devtools.remote.client.RemoteClientConfiguration
;
...
@@ -55,7 +56,7 @@ public final class RemoteSpringApplication {
...
@@ -55,7 +56,7 @@ public final class RemoteSpringApplication {
Restarter
.
initialize
(
args
,
RestartInitializer
.
NONE
);
Restarter
.
initialize
(
args
,
RestartInitializer
.
NONE
);
SpringApplication
application
=
new
SpringApplication
(
SpringApplication
application
=
new
SpringApplication
(
RemoteClientConfiguration
.
class
);
RemoteClientConfiguration
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
application
.
setBanner
(
getBanner
());
application
.
setBanner
(
getBanner
());
application
.
setInitializers
(
getInitializers
());
application
.
setInitializers
(
getInitializers
());
application
.
setListeners
(
getListeners
());
application
.
setListeners
(
getListeners
());
...
...
spring-boot-devtools/src/test/java/org/springframework/boot/devtools/RemoteUrlPropertyExtractorTests.java
View file @
95f659f4
/*
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
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.
...
@@ -24,6 +24,7 @@ import org.junit.rules.ExpectedException;
...
@@ -24,6 +24,7 @@ import org.junit.rules.ExpectedException;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.WebApplicationType
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
...
@@ -85,7 +86,7 @@ public class RemoteUrlPropertyExtractorTests {
...
@@ -85,7 +86,7 @@ public class RemoteUrlPropertyExtractorTests {
private
ApplicationContext
doTest
(
String
...
args
)
{
private
ApplicationContext
doTest
(
String
...
args
)
{
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
application
.
addListeners
(
new
RemoteUrlPropertyExtractor
());
application
.
addListeners
(
new
RemoteUrlPropertyExtractor
());
return
application
.
run
(
args
);
return
application
.
run
(
args
);
}
}
...
...
spring-boot-devtools/src/test/java/org/springframework/boot/devtools/env/DevToolPropertiesIntegrationTests.java
View file @
95f659f4
/*
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
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.
...
@@ -27,6 +27,7 @@ import org.junit.rules.ExpectedException;
...
@@ -27,6 +27,7 @@ import org.junit.rules.ExpectedException;
import
org.springframework.beans.factory.NoSuchBeanDefinitionException
;
import
org.springframework.beans.factory.NoSuchBeanDefinitionException
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.WebApplicationType
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.devtools.restart.RestartInitializer
;
import
org.springframework.boot.devtools.restart.RestartInitializer
;
import
org.springframework.boot.devtools.restart.Restarter
;
import
org.springframework.boot.devtools.restart.Restarter
;
...
@@ -63,7 +64,7 @@ public class DevToolPropertiesIntegrationTests {
...
@@ -63,7 +64,7 @@ public class DevToolPropertiesIntegrationTests {
public
void
classPropertyConditionIsAffectedByDevToolProperties
()
{
public
void
classPropertyConditionIsAffectedByDevToolProperties
()
{
SpringApplication
application
=
new
SpringApplication
(
SpringApplication
application
=
new
SpringApplication
(
ClassConditionConfiguration
.
class
);
ClassConditionConfiguration
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
this
.
context
=
application
.
run
();
this
.
context
=
application
.
run
();
this
.
context
.
getBean
(
ClassConditionConfiguration
.
class
);
this
.
context
.
getBean
(
ClassConditionConfiguration
.
class
);
}
}
...
@@ -72,7 +73,7 @@ public class DevToolPropertiesIntegrationTests {
...
@@ -72,7 +73,7 @@ public class DevToolPropertiesIntegrationTests {
public
void
beanMethodPropertyConditionIsAffectedByDevToolProperties
()
{
public
void
beanMethodPropertyConditionIsAffectedByDevToolProperties
()
{
SpringApplication
application
=
new
SpringApplication
(
SpringApplication
application
=
new
SpringApplication
(
BeanConditionConfiguration
.
class
);
BeanConditionConfiguration
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
this
.
context
=
application
.
run
();
this
.
context
=
application
.
run
();
this
.
context
.
getBean
(
MyBean
.
class
);
this
.
context
.
getBean
(
MyBean
.
class
);
}
}
...
@@ -84,7 +85,7 @@ public class DevToolPropertiesIntegrationTests {
...
@@ -84,7 +85,7 @@ public class DevToolPropertiesIntegrationTests {
Restarter
.
disable
();
Restarter
.
disable
();
SpringApplication
application
=
new
SpringApplication
(
SpringApplication
application
=
new
SpringApplication
(
BeanConditionConfiguration
.
class
);
BeanConditionConfiguration
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
this
.
context
=
application
.
run
();
this
.
context
=
application
.
run
();
this
.
thrown
.
expect
(
NoSuchBeanDefinitionException
.
class
);
this
.
thrown
.
expect
(
NoSuchBeanDefinitionException
.
class
);
this
.
context
.
getBean
(
MyBean
.
class
);
this
.
context
.
getBean
(
MyBean
.
class
);
...
@@ -97,7 +98,7 @@ public class DevToolPropertiesIntegrationTests {
...
@@ -97,7 +98,7 @@ public class DevToolPropertiesIntegrationTests {
Restarter
.
disable
();
Restarter
.
disable
();
SpringApplication
application
=
new
SpringApplication
(
SpringApplication
application
=
new
SpringApplication
(
BeanConditionConfiguration
.
class
);
BeanConditionConfiguration
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
application
.
setDefaultProperties
(
Collections
.<
String
,
Object
>
singletonMap
(
application
.
setDefaultProperties
(
Collections
.<
String
,
Object
>
singletonMap
(
"spring.devtools.remote.secret"
,
"donttell"
));
"spring.devtools.remote.secret"
,
"donttell"
));
this
.
context
=
application
.
run
();
this
.
context
=
application
.
run
();
...
...
spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/RestartScopeInitializerTests.java
View file @
95f659f4
/*
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
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.
...
@@ -21,6 +21,7 @@ import java.util.concurrent.atomic.AtomicInteger;
...
@@ -21,6 +21,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.WebApplicationType
;
import
org.springframework.context.ApplicationListener
;
import
org.springframework.context.ApplicationListener
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
...
@@ -54,7 +55,7 @@ public class RestartScopeInitializerTests {
...
@@ -54,7 +55,7 @@ public class RestartScopeInitializerTests {
private
ConfigurableApplicationContext
runApplication
()
{
private
ConfigurableApplicationContext
runApplication
()
{
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
return
application
.
run
();
return
application
.
run
();
}
}
...
...
spring-boot-samples/spring-boot-sample-jersey1/src/main/java/sample/jersey1/SampleJersey1Application.java
View file @
95f659f4
/*
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
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.
...
@@ -22,6 +22,7 @@ import javax.ws.rs.Produces;
...
@@ -22,6 +22,7 @@ import javax.ws.rs.Produces;
import
com.sun.jersey.spi.container.servlet.ServletContainer
;
import
com.sun.jersey.spi.container.servlet.ServletContainer
;
import
org.springframework.boot.WebApplicationType
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory
;
import
org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory
;
...
@@ -54,7 +55,8 @@ public class SampleJersey1Application {
...
@@ -54,7 +55,8 @@ public class SampleJersey1Application {
}
}
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
new
SpringApplicationBuilder
(
SampleJersey1Application
.
class
).
web
(
true
).
run
(
args
);
new
SpringApplicationBuilder
(
SampleJersey1Application
.
class
)
.
web
(
WebApplicationType
.
SERVLET
).
run
(
args
);
}
}
}
}
spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/SpringBootDependencyInjectionTestExecutionListenerTests.java
View file @
95f659f4
/*
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
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.
...
@@ -20,6 +20,7 @@ import org.junit.Rule;
...
@@ -20,6 +20,7 @@ import org.junit.Rule;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.WebApplicationType
;
import
org.springframework.boot.autoconfigure.ImportAutoConfiguration
;
import
org.springframework.boot.autoconfigure.ImportAutoConfiguration
;
import
org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration
;
import
org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration
;
import
org.springframework.boot.test.rule.OutputCapture
;
import
org.springframework.boot.test.rule.OutputCapture
;
...
@@ -59,7 +60,7 @@ public class SpringBootDependencyInjectionTestExecutionListenerTests {
...
@@ -59,7 +60,7 @@ public class SpringBootDependencyInjectionTestExecutionListenerTests {
TestContext
testContext
=
mock
(
TestContext
.
class
);
TestContext
testContext
=
mock
(
TestContext
.
class
);
given
(
testContext
.
getTestInstance
()).
willThrow
(
new
IllegalStateException
());
given
(
testContext
.
getTestInstance
()).
willThrow
(
new
IllegalStateException
());
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
ConfigurableApplicationContext
applicationContext
=
application
.
run
();
ConfigurableApplicationContext
applicationContext
=
application
.
run
();
given
(
testContext
.
getApplicationContext
()).
willReturn
(
applicationContext
);
given
(
testContext
.
getApplicationContext
()).
willReturn
(
applicationContext
);
try
{
try
{
...
...
spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootContextLoader.java
View file @
95f659f4
...
@@ -26,6 +26,7 @@ import java.util.Set;
...
@@ -26,6 +26,7 @@ import java.util.Set;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.WebApplicationType
;
import
org.springframework.boot.bind.RelaxedPropertyResolver
;
import
org.springframework.boot.bind.RelaxedPropertyResolver
;
import
org.springframework.boot.test.mock.web.SpringBootMockServletContext
;
import
org.springframework.boot.test.mock.web.SpringBootMockServletContext
;
import
org.springframework.boot.test.util.EnvironmentTestUtils
;
import
org.springframework.boot.test.util.EnvironmentTestUtils
;
...
@@ -108,13 +109,13 @@ public class SpringBootContextLoader extends AbstractContextLoader {
...
@@ -108,13 +109,13 @@ public class SpringBootContextLoader extends AbstractContextLoader {
List
<
ApplicationContextInitializer
<?>>
initializers
=
getInitializers
(
config
,
List
<
ApplicationContextInitializer
<?>>
initializers
=
getInitializers
(
config
,
application
);
application
);
if
(
config
instanceof
WebMergedContextConfiguration
)
{
if
(
config
instanceof
WebMergedContextConfiguration
)
{
application
.
setWeb
Environment
(
true
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
SERVLET
);
if
(!
isEmbeddedWebEnvironment
(
config
))
{
if
(!
isEmbeddedWebEnvironment
(
config
))
{
new
WebConfigurer
().
configure
(
config
,
application
,
initializers
);
new
WebConfigurer
().
configure
(
config
,
application
,
initializers
);
}
}
}
}
else
{
else
{
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
}
}
application
.
setInitializers
(
initializers
);
application
.
setInitializers
(
initializers
);
ConfigurableApplicationContext
context
=
application
.
run
();
ConfigurableApplicationContext
context
=
application
.
run
();
...
...
spring-boot/src/main/java/org/springframework/boot/SpringApplication.java
View file @
95f659f4
...
@@ -222,7 +222,7 @@ public class SpringApplication {
...
@@ -222,7 +222,7 @@ public class SpringApplication {
private
Class
<?
extends
ConfigurableApplicationContext
>
applicationContextClass
;
private
Class
<?
extends
ConfigurableApplicationContext
>
applicationContextClass
;
private
boolean
webEnvironment
;
private
WebApplicationType
webApplicationType
;
private
boolean
headless
=
true
;
private
boolean
headless
=
true
;
...
@@ -269,20 +269,20 @@ public class SpringApplication {
...
@@ -269,20 +269,20 @@ public class SpringApplication {
if
(
sources
!=
null
&&
sources
.
length
>
0
)
{
if
(
sources
!=
null
&&
sources
.
length
>
0
)
{
this
.
sources
.
addAll
(
Arrays
.
asList
(
sources
));
this
.
sources
.
addAll
(
Arrays
.
asList
(
sources
));
}
}
this
.
web
Environment
=
deduceWebEnvironment
();
this
.
web
ApplicationType
=
deduceWebApplication
();
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
boolean
deduceWebEnvironment
()
{
private
WebApplicationType
deduceWebApplication
()
{
for
(
String
className
:
WEB_ENVIRONMENT_CLASSES
)
{
for
(
String
className
:
WEB_ENVIRONMENT_CLASSES
)
{
if
(!
ClassUtils
.
isPresent
(
className
,
null
))
{
if
(!
ClassUtils
.
isPresent
(
className
,
null
))
{
return
false
;
return
WebApplicationType
.
NONE
;
}
}
}
}
return
true
;
return
WebApplicationType
.
SERVLET
;
}
}
private
Class
<?>
deduceMainApplicationClass
()
{
private
Class
<?>
deduceMainApplicationClass
()
{
...
@@ -349,7 +349,8 @@ public class SpringApplication {
...
@@ -349,7 +349,8 @@ public class SpringApplication {
ConfigurableEnvironment
environment
=
getOrCreateEnvironment
();
ConfigurableEnvironment
environment
=
getOrCreateEnvironment
();
configureEnvironment
(
environment
,
applicationArguments
.
getSourceArgs
());
configureEnvironment
(
environment
,
applicationArguments
.
getSourceArgs
());
listeners
.
environmentPrepared
(
environment
);
listeners
.
environmentPrepared
(
environment
);
if
(
isWebEnvironment
(
environment
)
&&
!
this
.
webEnvironment
)
{
if
(
isWebEnvironment
(
environment
)
&&
this
.
webApplicationType
==
WebApplicationType
.
NONE
)
{
environment
=
convertToStandardEnvironment
(
environment
);
environment
=
convertToStandardEnvironment
(
environment
);
}
}
return
environment
;
return
environment
;
...
@@ -446,7 +447,7 @@ public class SpringApplication {
...
@@ -446,7 +447,7 @@ public class SpringApplication {
if
(
this
.
environment
!=
null
)
{
if
(
this
.
environment
!=
null
)
{
return
this
.
environment
;
return
this
.
environment
;
}
}
if
(
this
.
web
Environment
)
{
if
(
this
.
web
ApplicationType
==
WebApplicationType
.
SERVLET
)
{
return
new
StandardServletEnvironment
();
return
new
StandardServletEnvironment
();
}
}
return
new
StandardEnvironment
();
return
new
StandardEnvironment
();
...
@@ -566,7 +567,8 @@ public class SpringApplication {
...
@@ -566,7 +567,8 @@ public class SpringApplication {
* @param environment the environment to bind
* @param environment the environment to bind
*/
*/
protected
void
bindToSpringApplication
(
ConfigurableEnvironment
environment
)
{
protected
void
bindToSpringApplication
(
ConfigurableEnvironment
environment
)
{
PropertiesConfigurationFactory
<
SpringApplication
>
binder
=
new
PropertiesConfigurationFactory
<>(
this
);
PropertiesConfigurationFactory
<
SpringApplication
>
binder
=
new
PropertiesConfigurationFactory
<>(
this
);
ConversionService
conversionService
=
new
DefaultConversionService
();
ConversionService
conversionService
=
new
DefaultConversionService
();
binder
.
setTargetName
(
"spring.main"
);
binder
.
setTargetName
(
"spring.main"
);
binder
.
setConversionService
(
conversionService
);
binder
.
setConversionService
(
conversionService
);
...
@@ -604,8 +606,9 @@ public class SpringApplication {
...
@@ -604,8 +606,9 @@ public class SpringApplication {
Class
<?>
contextClass
=
this
.
applicationContextClass
;
Class
<?>
contextClass
=
this
.
applicationContextClass
;
if
(
contextClass
==
null
)
{
if
(
contextClass
==
null
)
{
try
{
try
{
contextClass
=
Class
.
forName
(
this
.
webEnvironment
contextClass
=
Class
?
DEFAULT_WEB_CONTEXT_CLASS
:
DEFAULT_CONTEXT_CLASS
);
.
forName
(
this
.
webApplicationType
==
WebApplicationType
.
SERVLET
?
DEFAULT_WEB_CONTEXT_CLASS
:
DEFAULT_CONTEXT_CLASS
);
}
}
catch
(
ClassNotFoundException
ex
)
{
catch
(
ClassNotFoundException
ex
)
{
throw
new
IllegalStateException
(
throw
new
IllegalStateException
(
...
@@ -953,18 +956,44 @@ public class SpringApplication {
...
@@ -953,18 +956,44 @@ public class SpringApplication {
* Returns whether this {@link SpringApplication} is running within a web environment.
* Returns whether this {@link SpringApplication} is running within a web environment.
* @return {@code true} if running within a web environment, otherwise {@code false}.
* @return {@code true} if running within a web environment, otherwise {@code false}.
* @see #setWebEnvironment(boolean)
* @see #setWebEnvironment(boolean)
* @deprecated since 2.0.0 in favor of {@link #getWebApplicationType()}
*/
*/
@Deprecated
public
boolean
isWebEnvironment
()
{
public
boolean
isWebEnvironment
()
{
return
this
.
webEnvironment
;
return
this
.
webApplicationType
==
WebApplicationType
.
SERVLET
;
}
/**
* Returns the type of web application that is being run.
* @return the type of web application
* @since 2.0.0
*/
public
WebApplicationType
getWebApplicationType
()
{
return
this
.
webApplicationType
;
}
}
/**
/**
* Sets if this application is running within a web environment. If not specified will
* Sets if this application is running within a web environment. If not specified will
* attempt to deduce the environment based on the classpath.
* attempt to deduce the environment based on the classpath.
* @param webEnvironment if the application is running in a web environment
* @param webEnvironment if the application is running in a web environment
* @deprecated since 2.0.0 in favor of
* {@link #setWebApplicationType(WebApplicationType)}
*/
*/
@Deprecated
public
void
setWebEnvironment
(
boolean
webEnvironment
)
{
public
void
setWebEnvironment
(
boolean
webEnvironment
)
{
this
.
webEnvironment
=
webEnvironment
;
this
.
webApplicationType
=
webEnvironment
?
WebApplicationType
.
SERVLET
:
WebApplicationType
.
NONE
;
}
/**
* Sets the type of web application to be run. If not explicity set the type of web
* application will be deduced based on the classpath.
* @param webApplicationType the web application type
* @since 2.0.0
*/
public
void
setWebApplicationType
(
WebApplicationType
webApplicationType
)
{
Assert
.
notNull
(
webApplicationType
,
"WebApplicationType must not be null"
);
this
.
webApplicationType
=
webApplicationType
;
}
}
/**
/**
...
@@ -1113,7 +1142,7 @@ public class SpringApplication {
...
@@ -1113,7 +1142,7 @@ public class SpringApplication {
Class
<?
extends
ConfigurableApplicationContext
>
applicationContextClass
)
{
Class
<?
extends
ConfigurableApplicationContext
>
applicationContextClass
)
{
this
.
applicationContextClass
=
applicationContextClass
;
this
.
applicationContextClass
=
applicationContextClass
;
if
(!
isWebApplicationContext
(
applicationContextClass
))
{
if
(!
isWebApplicationContext
(
applicationContextClass
))
{
this
.
web
Environment
=
false
;
this
.
web
ApplicationType
=
WebApplicationType
.
NONE
;
}
}
}
}
...
...
spring-boot/src/main/java/org/springframework/boot/WebApplicationType.java
0 → 100644
View file @
95f659f4
/*
* Copyright 2012-2017 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
;
/**
* An enumeration of possible types of web application.
*
* @author Andy Wilkinson
* @since 2.0.0
*/
public
enum
WebApplicationType
{
/**
* The application should not run as a web application and should not start an
* embedded web container.
*/
NONE
,
/**
* The application should run as a servlet-based web application and should start an
* embedded servlet container.
*/
SERVLET
;
}
spring-boot/src/main/java/org/springframework/boot/builder/SpringApplicationBuilder.java
View file @
95f659f4
/*
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
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.
...
@@ -30,6 +30,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
...
@@ -30,6 +30,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
import
org.springframework.beans.factory.support.BeanNameGenerator
;
import
org.springframework.beans.factory.support.BeanNameGenerator
;
import
org.springframework.boot.Banner
;
import
org.springframework.boot.Banner
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.WebApplicationType
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContextInitializer
;
import
org.springframework.context.ApplicationContextInitializer
;
import
org.springframework.context.ApplicationListener
;
import
org.springframework.context.ApplicationListener
;
...
@@ -296,12 +297,26 @@ public class SpringApplicationBuilder {
...
@@ -296,12 +297,26 @@ public class SpringApplicationBuilder {
* classpath if not set).
* classpath if not set).
* @param webEnvironment the flag to set
* @param webEnvironment the flag to set
* @return the current builder
* @return the current builder
* @deprecated since 2.0.0 in favour of {@link #web(WebApplicationType)}
*/
*/
@Deprecated
public
SpringApplicationBuilder
web
(
boolean
webEnvironment
)
{
public
SpringApplicationBuilder
web
(
boolean
webEnvironment
)
{
this
.
application
.
setWebEnvironment
(
webEnvironment
);
this
.
application
.
setWebEnvironment
(
webEnvironment
);
return
this
;
return
this
;
}
}
/**
* Flag to explicity request a specific type of web application. Auto-detected based
* on the classpath if not set.
* @param webApplication the type of web application
* @return the current builder
* @since 2.0.0
*/
public
SpringApplicationBuilder
web
(
WebApplicationType
webApplication
)
{
this
.
application
.
setWebApplicationType
(
webApplication
);
return
this
;
}
/**
/**
* Flag to indicate the startup information should be logged.
* Flag to indicate the startup information should be logged.
* @param logStartupInfo the flag to set. Default true.
* @param logStartupInfo the flag to set. Default true.
...
...
spring-boot/src/test/java/org/springframework/boot/BannerTests.java
View file @
95f659f4
/*
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
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.
...
@@ -72,7 +72,7 @@ public class BannerTests {
...
@@ -72,7 +72,7 @@ public class BannerTests {
@Test
@Test
public
void
testDefaultBanner
()
throws
Exception
{
public
void
testDefaultBanner
()
throws
Exception
{
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
this
.
context
=
application
.
run
();
this
.
context
=
application
.
run
();
assertThat
(
this
.
out
.
toString
()).
contains
(
":: Spring Boot ::"
);
assertThat
(
this
.
out
.
toString
()).
contains
(
":: Spring Boot ::"
);
}
}
...
@@ -80,7 +80,7 @@ public class BannerTests {
...
@@ -80,7 +80,7 @@ public class BannerTests {
@Test
@Test
public
void
testDefaultBannerInLog
()
throws
Exception
{
public
void
testDefaultBannerInLog
()
throws
Exception
{
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
this
.
context
=
application
.
run
();
this
.
context
=
application
.
run
();
assertThat
(
this
.
out
.
toString
()).
contains
(
":: Spring Boot ::"
);
assertThat
(
this
.
out
.
toString
()).
contains
(
":: Spring Boot ::"
);
}
}
...
@@ -88,7 +88,7 @@ public class BannerTests {
...
@@ -88,7 +88,7 @@ public class BannerTests {
@Test
@Test
public
void
testCustomBanner
()
throws
Exception
{
public
void
testCustomBanner
()
throws
Exception
{
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
application
.
setBanner
(
new
DummyBanner
());
application
.
setBanner
(
new
DummyBanner
());
this
.
context
=
application
.
run
();
this
.
context
=
application
.
run
();
assertThat
(
this
.
out
.
toString
()).
contains
(
"My Banner"
);
assertThat
(
this
.
out
.
toString
()).
contains
(
"My Banner"
);
...
@@ -97,7 +97,7 @@ public class BannerTests {
...
@@ -97,7 +97,7 @@ public class BannerTests {
@Test
@Test
public
void
testBannerInContext
()
throws
Exception
{
public
void
testBannerInContext
()
throws
Exception
{
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
this
.
context
=
application
.
run
();
this
.
context
=
application
.
run
();
assertThat
(
this
.
context
.
containsBean
(
"springBootBanner"
)).
isTrue
();
assertThat
(
this
.
context
.
containsBean
(
"springBootBanner"
)).
isTrue
();
}
}
...
@@ -105,7 +105,7 @@ public class BannerTests {
...
@@ -105,7 +105,7 @@ public class BannerTests {
@Test
@Test
public
void
testCustomBannerInContext
()
throws
Exception
{
public
void
testCustomBannerInContext
()
throws
Exception
{
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
Banner
banner
=
mock
(
Banner
.
class
);
Banner
banner
=
mock
(
Banner
.
class
);
application
.
setBanner
(
banner
);
application
.
setBanner
(
banner
);
this
.
context
=
application
.
run
();
this
.
context
=
application
.
run
();
...
@@ -124,7 +124,7 @@ public class BannerTests {
...
@@ -124,7 +124,7 @@ public class BannerTests {
public
void
testDisableBannerInContext
()
throws
Exception
{
public
void
testDisableBannerInContext
()
throws
Exception
{
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setBannerMode
(
Mode
.
OFF
);
application
.
setBannerMode
(
Mode
.
OFF
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
this
.
context
=
application
.
run
();
this
.
context
=
application
.
run
();
assertThat
(
this
.
context
.
containsBean
(
"springBootBanner"
)).
isFalse
();
assertThat
(
this
.
context
.
containsBean
(
"springBootBanner"
)).
isFalse
();
}
}
...
...
spring-boot/src/test/java/org/springframework/boot/ReproTests.java
View file @
95f659f4
/*
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
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.
...
@@ -46,7 +46,7 @@ public class ReproTests {
...
@@ -46,7 +46,7 @@ public class ReproTests {
// gh-308
// gh-308
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
this
.
context
=
application
.
run
(
this
.
context
=
application
.
run
(
"--spring.config.name=enableprofileviaapplicationproperties"
,
"--spring.config.name=enableprofileviaapplicationproperties"
,
"--spring.profiles.active=dev"
);
"--spring.profiles.active=dev"
);
...
@@ -58,7 +58,7 @@ public class ReproTests {
...
@@ -58,7 +58,7 @@ public class ReproTests {
public
void
activeProfilesWithYamlAndCommandLine
()
throws
Exception
{
public
void
activeProfilesWithYamlAndCommandLine
()
throws
Exception
{
// gh-322, gh-342
// gh-322, gh-342
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
String
configName
=
"--spring.config.name=activeprofilerepro"
;
String
configName
=
"--spring.config.name=activeprofilerepro"
;
this
.
context
=
application
.
run
(
configName
,
"--spring.profiles.active=B"
);
this
.
context
=
application
.
run
(
configName
,
"--spring.profiles.active=B"
);
assertVersionProperty
(
this
.
context
,
"B"
,
"B"
);
assertVersionProperty
(
this
.
context
,
"B"
,
"B"
);
...
@@ -68,7 +68,7 @@ public class ReproTests {
...
@@ -68,7 +68,7 @@ public class ReproTests {
public
void
activeProfilesWithYamlOnly
()
throws
Exception
{
public
void
activeProfilesWithYamlOnly
()
throws
Exception
{
// gh-322, gh-342
// gh-322, gh-342
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
String
configName
=
"--spring.config.name=activeprofilerepro"
;
String
configName
=
"--spring.config.name=activeprofilerepro"
;
this
.
context
=
application
.
run
(
configName
);
this
.
context
=
application
.
run
(
configName
);
assertVersionProperty
(
this
.
context
,
"B"
,
"B"
);
assertVersionProperty
(
this
.
context
,
"B"
,
"B"
);
...
@@ -78,7 +78,7 @@ public class ReproTests {
...
@@ -78,7 +78,7 @@ public class ReproTests {
public
void
orderActiveProfilesWithYamlOnly
()
throws
Exception
{
public
void
orderActiveProfilesWithYamlOnly
()
throws
Exception
{
// gh-322, gh-342
// gh-322, gh-342
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
String
configName
=
"--spring.config.name=activeprofilerepro-ordered"
;
String
configName
=
"--spring.config.name=activeprofilerepro-ordered"
;
this
.
context
=
application
.
run
(
configName
);
this
.
context
=
application
.
run
(
configName
);
assertVersionProperty
(
this
.
context
,
"B"
,
"A"
,
"B"
);
assertVersionProperty
(
this
.
context
,
"B"
,
"A"
,
"B"
);
...
@@ -88,7 +88,7 @@ public class ReproTests {
...
@@ -88,7 +88,7 @@ public class ReproTests {
public
void
commandLineBeatsProfilesWithYaml
()
throws
Exception
{
public
void
commandLineBeatsProfilesWithYaml
()
throws
Exception
{
// gh-322, gh-342
// gh-322, gh-342
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
String
configName
=
"--spring.config.name=activeprofilerepro"
;
String
configName
=
"--spring.config.name=activeprofilerepro"
;
this
.
context
=
application
.
run
(
configName
,
"--spring.profiles.active=C"
);
this
.
context
=
application
.
run
(
configName
,
"--spring.profiles.active=C"
);
assertVersionProperty
(
this
.
context
,
"C"
,
"C"
);
assertVersionProperty
(
this
.
context
,
"C"
,
"C"
);
...
@@ -98,7 +98,7 @@ public class ReproTests {
...
@@ -98,7 +98,7 @@ public class ReproTests {
public
void
orderProfilesWithYaml
()
throws
Exception
{
public
void
orderProfilesWithYaml
()
throws
Exception
{
// gh-322, gh-342
// gh-322, gh-342
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
String
configName
=
"--spring.config.name=activeprofilerepro"
;
String
configName
=
"--spring.config.name=activeprofilerepro"
;
this
.
context
=
application
.
run
(
configName
,
"--spring.profiles.active=A,C"
);
this
.
context
=
application
.
run
(
configName
,
"--spring.profiles.active=A,C"
);
assertVersionProperty
(
this
.
context
,
"C"
,
"A"
,
"C"
);
assertVersionProperty
(
this
.
context
,
"C"
,
"A"
,
"C"
);
...
@@ -108,7 +108,7 @@ public class ReproTests {
...
@@ -108,7 +108,7 @@ public class ReproTests {
public
void
reverseOrderOfProfilesWithYaml
()
throws
Exception
{
public
void
reverseOrderOfProfilesWithYaml
()
throws
Exception
{
// gh-322, gh-342
// gh-322, gh-342
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
String
configName
=
"--spring.config.name=activeprofilerepro"
;
String
configName
=
"--spring.config.name=activeprofilerepro"
;
this
.
context
=
application
.
run
(
configName
,
"--spring.profiles.active=C,A"
);
this
.
context
=
application
.
run
(
configName
,
"--spring.profiles.active=C,A"
);
assertVersionProperty
(
this
.
context
,
"A"
,
"C"
,
"A"
);
assertVersionProperty
(
this
.
context
,
"A"
,
"C"
,
"A"
);
...
@@ -118,7 +118,7 @@ public class ReproTests {
...
@@ -118,7 +118,7 @@ public class ReproTests {
public
void
activeProfilesWithYamlAndCommandLineAndNoOverride
()
throws
Exception
{
public
void
activeProfilesWithYamlAndCommandLineAndNoOverride
()
throws
Exception
{
// gh-322, gh-342
// gh-322, gh-342
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
String
configName
=
"--spring.config.name=activeprofilerepro-without-override"
;
String
configName
=
"--spring.config.name=activeprofilerepro-without-override"
;
this
.
context
=
application
.
run
(
configName
,
"--spring.profiles.active=B"
);
this
.
context
=
application
.
run
(
configName
,
"--spring.profiles.active=B"
);
assertVersionProperty
(
this
.
context
,
"B"
,
"B"
);
assertVersionProperty
(
this
.
context
,
"B"
,
"B"
);
...
@@ -128,7 +128,7 @@ public class ReproTests {
...
@@ -128,7 +128,7 @@ public class ReproTests {
public
void
activeProfilesWithYamlOnlyAndNoOverride
()
throws
Exception
{
public
void
activeProfilesWithYamlOnlyAndNoOverride
()
throws
Exception
{
// gh-322, gh-342
// gh-322, gh-342
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
String
configName
=
"--spring.config.name=activeprofilerepro-without-override"
;
String
configName
=
"--spring.config.name=activeprofilerepro-without-override"
;
this
.
context
=
application
.
run
(
configName
);
this
.
context
=
application
.
run
(
configName
);
assertVersionProperty
(
this
.
context
,
null
);
assertVersionProperty
(
this
.
context
,
null
);
...
@@ -138,7 +138,7 @@ public class ReproTests {
...
@@ -138,7 +138,7 @@ public class ReproTests {
public
void
commandLineBeatsProfilesWithYamlAndNoOverride
()
throws
Exception
{
public
void
commandLineBeatsProfilesWithYamlAndNoOverride
()
throws
Exception
{
// gh-322, gh-342
// gh-322, gh-342
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
String
configName
=
"--spring.config.name=activeprofilerepro-without-override"
;
String
configName
=
"--spring.config.name=activeprofilerepro-without-override"
;
this
.
context
=
application
.
run
(
configName
,
"--spring.profiles.active=C"
);
this
.
context
=
application
.
run
(
configName
,
"--spring.profiles.active=C"
);
assertVersionProperty
(
this
.
context
,
"C"
,
"C"
);
assertVersionProperty
(
this
.
context
,
"C"
,
"C"
);
...
@@ -148,7 +148,7 @@ public class ReproTests {
...
@@ -148,7 +148,7 @@ public class ReproTests {
public
void
orderProfilesWithYamlAndNoOverride
()
throws
Exception
{
public
void
orderProfilesWithYamlAndNoOverride
()
throws
Exception
{
// gh-322, gh-342
// gh-322, gh-342
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
String
configName
=
"--spring.config.name=activeprofilerepro-without-override"
;
String
configName
=
"--spring.config.name=activeprofilerepro-without-override"
;
this
.
context
=
application
.
run
(
configName
,
"--spring.profiles.active=A,C"
);
this
.
context
=
application
.
run
(
configName
,
"--spring.profiles.active=A,C"
);
assertVersionProperty
(
this
.
context
,
"C"
,
"A"
,
"C"
);
assertVersionProperty
(
this
.
context
,
"C"
,
"A"
,
"C"
);
...
@@ -158,7 +158,7 @@ public class ReproTests {
...
@@ -158,7 +158,7 @@ public class ReproTests {
public
void
reverseOrderOfProfilesWithYamlAndNoOverride
()
throws
Exception
{
public
void
reverseOrderOfProfilesWithYamlAndNoOverride
()
throws
Exception
{
// gh-322, gh-342
// gh-322, gh-342
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
String
configName
=
"--spring.config.name=activeprofilerepro-without-override"
;
String
configName
=
"--spring.config.name=activeprofilerepro-without-override"
;
this
.
context
=
application
.
run
(
configName
,
"--spring.profiles.active=C,A"
);
this
.
context
=
application
.
run
(
configName
,
"--spring.profiles.active=C,A"
);
assertVersionProperty
(
this
.
context
,
"A"
,
"C"
,
"A"
);
assertVersionProperty
(
this
.
context
,
"A"
,
"C"
,
"A"
);
...
...
spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java
View file @
95f659f4
This diff is collapsed.
Click to expand it.
spring-boot/src/test/java/org/springframework/boot/admin/SpringApplicationAdminMXBeanRegistrarTests.java
View file @
95f659f4
/*
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
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.
...
@@ -30,6 +30,7 @@ import org.junit.Test;
...
@@ -30,6 +30,7 @@ import org.junit.Test;
import
org.junit.rules.ExpectedException
;
import
org.junit.rules.ExpectedException
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.WebApplicationType
;
import
org.springframework.boot.context.event.ApplicationReadyEvent
;
import
org.springframework.boot.context.event.ApplicationReadyEvent
;
import
org.springframework.context.ApplicationListener
;
import
org.springframework.context.ApplicationListener
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.ConfigurableApplicationContext
;
...
@@ -74,7 +75,7 @@ public class SpringApplicationAdminMXBeanRegistrarTests {
...
@@ -74,7 +75,7 @@ public class SpringApplicationAdminMXBeanRegistrarTests {
public
void
validateReadyFlag
()
{
public
void
validateReadyFlag
()
{
final
ObjectName
objectName
=
createObjectName
(
OBJECT_NAME
);
final
ObjectName
objectName
=
createObjectName
(
OBJECT_NAME
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
application
.
addListeners
(
new
ApplicationListener
<
ContextRefreshedEvent
>()
{
application
.
addListeners
(
new
ApplicationListener
<
ContextRefreshedEvent
>()
{
@Override
@Override
public
void
onApplicationEvent
(
ContextRefreshedEvent
event
)
{
public
void
onApplicationEvent
(
ContextRefreshedEvent
event
)
{
...
@@ -114,7 +115,7 @@ public class SpringApplicationAdminMXBeanRegistrarTests {
...
@@ -114,7 +115,7 @@ public class SpringApplicationAdminMXBeanRegistrarTests {
public
void
environmentIsExposed
()
{
public
void
environmentIsExposed
()
{
final
ObjectName
objectName
=
createObjectName
(
OBJECT_NAME
);
final
ObjectName
objectName
=
createObjectName
(
OBJECT_NAME
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
this
.
context
=
application
.
run
(
"--foo.bar=blam"
);
this
.
context
=
application
.
run
(
"--foo.bar=blam"
);
assertThat
(
isApplicationReady
(
objectName
)).
isTrue
();
assertThat
(
isApplicationReady
(
objectName
)).
isTrue
();
assertThat
(
isApplicationEmbeddedWebApplication
(
objectName
)).
isFalse
();
assertThat
(
isApplicationEmbeddedWebApplication
(
objectName
)).
isFalse
();
...
@@ -126,7 +127,7 @@ public class SpringApplicationAdminMXBeanRegistrarTests {
...
@@ -126,7 +127,7 @@ public class SpringApplicationAdminMXBeanRegistrarTests {
public
void
shutdownApp
()
throws
InstanceNotFoundException
{
public
void
shutdownApp
()
throws
InstanceNotFoundException
{
final
ObjectName
objectName
=
createObjectName
(
OBJECT_NAME
);
final
ObjectName
objectName
=
createObjectName
(
OBJECT_NAME
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
this
.
context
=
application
.
run
();
this
.
context
=
application
.
run
();
assertThat
(
this
.
context
.
isRunning
()).
isTrue
();
assertThat
(
this
.
context
.
isRunning
()).
isTrue
();
invokeShutdown
(
objectName
);
invokeShutdown
(
objectName
);
...
...
spring-boot/src/test/java/org/springframework/boot/bind/SpringApplicationBindContextLoader.java
View file @
95f659f4
/*
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
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.
...
@@ -22,6 +22,7 @@ import java.util.LinkedHashSet;
...
@@ -22,6 +22,7 @@ import java.util.LinkedHashSet;
import
java.util.Map
;
import
java.util.Map
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.WebApplicationType
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.core.env.ConfigurableEnvironment
;
import
org.springframework.core.env.ConfigurableEnvironment
;
import
org.springframework.core.env.MapPropertySource
;
import
org.springframework.core.env.MapPropertySource
;
...
@@ -45,7 +46,7 @@ class SpringApplicationBindContextLoader extends AbstractContextLoader {
...
@@ -45,7 +46,7 @@ class SpringApplicationBindContextLoader extends AbstractContextLoader {
throws
Exception
{
throws
Exception
{
SpringApplication
application
=
new
SpringApplication
();
SpringApplication
application
=
new
SpringApplication
();
application
.
setMainApplicationClass
(
config
.
getTestClass
());
application
.
setMainApplicationClass
(
config
.
getTestClass
());
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
application
.
setSources
(
application
.
setSources
(
new
LinkedHashSet
<
Object
>(
Arrays
.
asList
(
config
.
getClasses
())));
new
LinkedHashSet
<
Object
>(
Arrays
.
asList
(
config
.
getClasses
())));
ConfigurableEnvironment
environment
=
new
StandardEnvironment
();
ConfigurableEnvironment
environment
=
new
StandardEnvironment
();
...
...
spring-boot/src/test/java/org/springframework/boot/builder/SpringApplicationBuilderTests.java
View file @
95f659f4
/*
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
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.
...
@@ -24,6 +24,7 @@ import org.junit.After;
...
@@ -24,6 +24,7 @@ import org.junit.After;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.springframework.boot.ApplicationArguments
;
import
org.springframework.boot.ApplicationArguments
;
import
org.springframework.boot.WebApplicationType
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContextInitializer
;
import
org.springframework.context.ApplicationContextInitializer
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.ConfigurableApplicationContext
;
...
@@ -203,7 +204,7 @@ public class SpringApplicationBuilderTests {
...
@@ -203,7 +204,7 @@ public class SpringApplicationBuilderTests {
public
void
parentFirstCreationWithProfileAndDefaultArgs
()
throws
Exception
{
public
void
parentFirstCreationWithProfileAndDefaultArgs
()
throws
Exception
{
SpringApplicationBuilder
application
=
new
SpringApplicationBuilder
(
SpringApplicationBuilder
application
=
new
SpringApplicationBuilder
(
ExampleConfig
.
class
).
profiles
(
"node"
).
properties
(
"transport=redis"
)
ExampleConfig
.
class
).
profiles
(
"node"
).
properties
(
"transport=redis"
)
.
child
(
ChildConfig
.
class
).
web
(
false
);
.
child
(
ChildConfig
.
class
).
web
(
WebApplicationType
.
NONE
);
this
.
context
=
application
.
run
();
this
.
context
=
application
.
run
();
assertThat
(
this
.
context
.
getEnvironment
().
acceptsProfiles
(
"node"
)).
isTrue
();
assertThat
(
this
.
context
.
getEnvironment
().
acceptsProfiles
(
"node"
)).
isTrue
();
assertThat
(
this
.
context
.
getEnvironment
().
getProperty
(
"transport"
))
assertThat
(
this
.
context
.
getEnvironment
().
getProperty
(
"transport"
))
...
@@ -220,7 +221,8 @@ public class SpringApplicationBuilderTests {
...
@@ -220,7 +221,8 @@ public class SpringApplicationBuilderTests {
public
void
parentFirstWithDifferentProfile
()
throws
Exception
{
public
void
parentFirstWithDifferentProfile
()
throws
Exception
{
SpringApplicationBuilder
application
=
new
SpringApplicationBuilder
(
SpringApplicationBuilder
application
=
new
SpringApplicationBuilder
(
ExampleConfig
.
class
).
profiles
(
"node"
).
properties
(
"transport=redis"
)
ExampleConfig
.
class
).
profiles
(
"node"
).
properties
(
"transport=redis"
)
.
child
(
ChildConfig
.
class
).
profiles
(
"admin"
).
web
(
false
);
.
child
(
ChildConfig
.
class
).
profiles
(
"admin"
)
.
web
(
WebApplicationType
.
NONE
);
this
.
context
=
application
.
run
();
this
.
context
=
application
.
run
();
assertThat
(
this
.
context
.
getEnvironment
().
acceptsProfiles
(
"node"
,
"admin"
))
assertThat
(
this
.
context
.
getEnvironment
().
acceptsProfiles
(
"node"
,
"admin"
))
.
isTrue
();
.
isTrue
();
...
@@ -233,7 +235,7 @@ public class SpringApplicationBuilderTests {
...
@@ -233,7 +235,7 @@ public class SpringApplicationBuilderTests {
SpringApplicationBuilder
shared
=
new
SpringApplicationBuilder
(
SpringApplicationBuilder
shared
=
new
SpringApplicationBuilder
(
ExampleConfig
.
class
).
profiles
(
"node"
).
properties
(
"transport=redis"
);
ExampleConfig
.
class
).
profiles
(
"node"
).
properties
(
"transport=redis"
);
SpringApplicationBuilder
application
=
shared
.
child
(
ChildConfig
.
class
)
SpringApplicationBuilder
application
=
shared
.
child
(
ChildConfig
.
class
)
.
profiles
(
"admin"
).
web
(
false
);
.
profiles
(
"admin"
).
web
(
WebApplicationType
.
NONE
);
shared
.
profiles
(
"parent"
);
shared
.
profiles
(
"parent"
);
this
.
context
=
application
.
run
();
this
.
context
=
application
.
run
();
assertThat
(
this
.
context
.
getEnvironment
().
acceptsProfiles
(
"node"
,
"admin"
))
assertThat
(
this
.
context
.
getEnvironment
().
acceptsProfiles
(
"node"
,
"admin"
))
...
@@ -249,7 +251,8 @@ public class SpringApplicationBuilderTests {
...
@@ -249,7 +251,8 @@ public class SpringApplicationBuilderTests {
SpringApplicationBuilder
application
=
new
SpringApplicationBuilder
(
SpringApplicationBuilder
application
=
new
SpringApplicationBuilder
(
ExampleConfig
.
class
).
environment
(
new
StandardEnvironment
())
ExampleConfig
.
class
).
environment
(
new
StandardEnvironment
())
.
profiles
(
"node"
).
properties
(
"transport=redis"
)
.
profiles
(
"node"
).
properties
(
"transport=redis"
)
.
child
(
ChildConfig
.
class
).
profiles
(
"admin"
).
web
(
false
);
.
child
(
ChildConfig
.
class
).
profiles
(
"admin"
)
.
web
(
WebApplicationType
.
NONE
);
this
.
context
=
application
.
run
();
this
.
context
=
application
.
run
();
assertThat
(
this
.
context
.
getEnvironment
().
acceptsProfiles
(
"node"
,
"admin"
))
assertThat
(
this
.
context
.
getEnvironment
().
acceptsProfiles
(
"node"
,
"admin"
))
.
isTrue
();
.
isTrue
();
...
@@ -273,7 +276,7 @@ public class SpringApplicationBuilderTests {
...
@@ -273,7 +276,7 @@ public class SpringApplicationBuilderTests {
@Test
@Test
public
void
initializersCreatedOnce
()
throws
Exception
{
public
void
initializersCreatedOnce
()
throws
Exception
{
SpringApplicationBuilder
application
=
new
SpringApplicationBuilder
(
SpringApplicationBuilder
application
=
new
SpringApplicationBuilder
(
ExampleConfig
.
class
).
web
(
false
);
ExampleConfig
.
class
).
web
(
WebApplicationType
.
NONE
);
this
.
context
=
application
.
run
();
this
.
context
=
application
.
run
();
assertThat
(
application
.
application
().
getInitializers
()).
hasSize
(
4
);
assertThat
(
application
.
application
().
getInitializers
()).
hasSize
(
4
);
}
}
...
@@ -281,7 +284,7 @@ public class SpringApplicationBuilderTests {
...
@@ -281,7 +284,7 @@ public class SpringApplicationBuilderTests {
@Test
@Test
public
void
initializersCreatedOnceForChild
()
throws
Exception
{
public
void
initializersCreatedOnceForChild
()
throws
Exception
{
SpringApplicationBuilder
application
=
new
SpringApplicationBuilder
(
SpringApplicationBuilder
application
=
new
SpringApplicationBuilder
(
ExampleConfig
.
class
).
child
(
ChildConfig
.
class
).
web
(
false
);
ExampleConfig
.
class
).
child
(
ChildConfig
.
class
).
web
(
WebApplicationType
.
NONE
);
this
.
context
=
application
.
run
();
this
.
context
=
application
.
run
();
assertThat
(
application
.
application
().
getInitializers
()).
hasSize
(
5
);
assertThat
(
application
.
application
().
getInitializers
()).
hasSize
(
5
);
}
}
...
@@ -289,7 +292,7 @@ public class SpringApplicationBuilderTests {
...
@@ -289,7 +292,7 @@ public class SpringApplicationBuilderTests {
@Test
@Test
public
void
initializersIncludeDefaults
()
throws
Exception
{
public
void
initializersIncludeDefaults
()
throws
Exception
{
SpringApplicationBuilder
application
=
new
SpringApplicationBuilder
(
SpringApplicationBuilder
application
=
new
SpringApplicationBuilder
(
ExampleConfig
.
class
).
web
(
false
).
initializers
(
ExampleConfig
.
class
).
web
(
WebApplicationType
.
NONE
).
initializers
(
new
ApplicationContextInitializer
<
ConfigurableApplicationContext
>()
{
new
ApplicationContextInitializer
<
ConfigurableApplicationContext
>()
{
@Override
@Override
public
void
initialize
(
public
void
initialize
(
...
...
spring-boot/src/test/java/org/springframework/boot/context/config/AnsiOutputApplicationListenerTests.java
View file @
95f659f4
/*
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
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.
...
@@ -24,6 +24,7 @@ import org.junit.Before;
...
@@ -24,6 +24,7 @@ import org.junit.Before;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.WebApplicationType
;
import
org.springframework.boot.ansi.AnsiOutput
;
import
org.springframework.boot.ansi.AnsiOutput
;
import
org.springframework.boot.ansi.AnsiOutput.Enabled
;
import
org.springframework.boot.ansi.AnsiOutput.Enabled
;
import
org.springframework.boot.ansi.AnsiOutputEnabledValue
;
import
org.springframework.boot.ansi.AnsiOutputEnabledValue
;
...
@@ -60,7 +61,7 @@ public class AnsiOutputApplicationListenerTests {
...
@@ -60,7 +61,7 @@ public class AnsiOutputApplicationListenerTests {
@Test
@Test
public
void
enabled
()
{
public
void
enabled
()
{
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
Map
<
String
,
Object
>
props
=
new
HashMap
<
String
,
Object
>();
Map
<
String
,
Object
>
props
=
new
HashMap
<
String
,
Object
>();
props
.
put
(
"spring.output.ansi.enabled"
,
"ALWAYS"
);
props
.
put
(
"spring.output.ansi.enabled"
,
"ALWAYS"
);
application
.
setDefaultProperties
(
props
);
application
.
setDefaultProperties
(
props
);
...
@@ -71,7 +72,7 @@ public class AnsiOutputApplicationListenerTests {
...
@@ -71,7 +72,7 @@ public class AnsiOutputApplicationListenerTests {
@Test
@Test
public
void
disabled
()
throws
Exception
{
public
void
disabled
()
throws
Exception
{
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
Map
<
String
,
Object
>
props
=
new
HashMap
<
String
,
Object
>();
Map
<
String
,
Object
>
props
=
new
HashMap
<
String
,
Object
>();
props
.
put
(
"spring.output.ansi.enabled"
,
"never"
);
props
.
put
(
"spring.output.ansi.enabled"
,
"never"
);
application
.
setDefaultProperties
(
props
);
application
.
setDefaultProperties
(
props
);
...
@@ -85,8 +86,8 @@ public class AnsiOutputApplicationListenerTests {
...
@@ -85,8 +86,8 @@ public class AnsiOutputApplicationListenerTests {
TestPropertySourceUtils
.
addInlinedPropertiesToEnvironment
(
environment
,
TestPropertySourceUtils
.
addInlinedPropertiesToEnvironment
(
environment
,
"spring.config.name=ansi"
);
"spring.config.name=ansi"
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWebEnvironment
(
false
);
application
.
setEnvironment
(
environment
);
application
.
setEnvironment
(
environment
);
application
.
setWebApplicationType
(
WebApplicationType
.
NONE
);
this
.
context
=
application
.
run
();
this
.
context
=
application
.
run
();
assertThat
(
AnsiOutputEnabledValue
.
get
()).
isEqualTo
(
Enabled
.
NEVER
);
assertThat
(
AnsiOutputEnabledValue
.
get
()).
isEqualTo
(
Enabled
.
NEVER
);
}
}
...
...
spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java
View file @
95f659f4
...
@@ -39,6 +39,7 @@ import org.slf4j.LoggerFactory;
...
@@ -39,6 +39,7 @@ import org.slf4j.LoggerFactory;
import
org.springframework.beans.CachedIntrospectionResults
;
import
org.springframework.beans.CachedIntrospectionResults
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.WebApplicationType
;
import
org.springframework.boot.context.config.ConfigFileApplicationListener.ConfigurationPropertySources
;
import
org.springframework.boot.context.config.ConfigFileApplicationListener.ConfigurationPropertySources
;
import
org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent
;
import
org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent
;
import
org.springframework.boot.context.event.ApplicationPreparedEvent
;
import
org.springframework.boot.context.event.ApplicationPreparedEvent
;
...
@@ -619,7 +620,7 @@ public class ConfigFileApplicationListenerTests {
...
@@ -619,7 +620,7 @@ public class ConfigFileApplicationListenerTests {
@Test
@Test
public
void
propertySourceAnnotation
()
throws
Exception
{
public
void
propertySourceAnnotation
()
throws
Exception
{
SpringApplication
application
=
new
SpringApplication
(
WithPropertySource
.
class
);
SpringApplication
application
=
new
SpringApplication
(
WithPropertySource
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
ConfigurableApplicationContext
context
=
application
.
run
();
ConfigurableApplicationContext
context
=
application
.
run
();
String
property
=
context
.
getEnvironment
().
getProperty
(
"the.property"
);
String
property
=
context
.
getEnvironment
().
getProperty
(
"the.property"
);
assertThat
(
property
).
isEqualTo
(
"fromspecificlocation"
);
assertThat
(
property
).
isEqualTo
(
"fromspecificlocation"
);
...
@@ -637,7 +638,7 @@ public class ConfigFileApplicationListenerTests {
...
@@ -637,7 +638,7 @@ public class ConfigFileApplicationListenerTests {
SpringApplication
application
=
new
SpringApplication
(
SpringApplication
application
=
new
SpringApplication
(
WithPropertySourcePlaceholders
.
class
);
WithPropertySourcePlaceholders
.
class
);
application
.
setEnvironment
(
this
.
environment
);
application
.
setEnvironment
(
this
.
environment
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
ConfigurableApplicationContext
context
=
application
.
run
();
ConfigurableApplicationContext
context
=
application
.
run
();
String
property
=
context
.
getEnvironment
().
getProperty
(
"the.property"
);
String
property
=
context
.
getEnvironment
().
getProperty
(
"the.property"
);
assertThat
(
property
).
isEqualTo
(
"fromspecificlocation"
);
assertThat
(
property
).
isEqualTo
(
"fromspecificlocation"
);
...
@@ -650,7 +651,7 @@ public class ConfigFileApplicationListenerTests {
...
@@ -650,7 +651,7 @@ public class ConfigFileApplicationListenerTests {
public
void
propertySourceAnnotationWithName
()
throws
Exception
{
public
void
propertySourceAnnotationWithName
()
throws
Exception
{
SpringApplication
application
=
new
SpringApplication
(
SpringApplication
application
=
new
SpringApplication
(
WithPropertySourceAndName
.
class
);
WithPropertySourceAndName
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
ConfigurableApplicationContext
context
=
application
.
run
();
ConfigurableApplicationContext
context
=
application
.
run
();
String
property
=
context
.
getEnvironment
().
getProperty
(
"the.property"
);
String
property
=
context
.
getEnvironment
().
getProperty
(
"the.property"
);
assertThat
(
property
).
isEqualTo
(
"fromspecificlocation"
);
assertThat
(
property
).
isEqualTo
(
"fromspecificlocation"
);
...
@@ -662,7 +663,7 @@ public class ConfigFileApplicationListenerTests {
...
@@ -662,7 +663,7 @@ public class ConfigFileApplicationListenerTests {
public
void
propertySourceAnnotationInProfile
()
throws
Exception
{
public
void
propertySourceAnnotationInProfile
()
throws
Exception
{
SpringApplication
application
=
new
SpringApplication
(
SpringApplication
application
=
new
SpringApplication
(
WithPropertySourceInProfile
.
class
);
WithPropertySourceInProfile
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
ConfigurableApplicationContext
context
=
application
ConfigurableApplicationContext
context
=
application
.
run
(
"--spring.profiles.active=myprofile"
);
.
run
(
"--spring.profiles.active=myprofile"
);
String
property
=
context
.
getEnvironment
().
getProperty
(
"the.property"
);
String
property
=
context
.
getEnvironment
().
getProperty
(
"the.property"
);
...
@@ -678,7 +679,7 @@ public class ConfigFileApplicationListenerTests {
...
@@ -678,7 +679,7 @@ public class ConfigFileApplicationListenerTests {
public
void
propertySourceAnnotationAndNonActiveProfile
()
throws
Exception
{
public
void
propertySourceAnnotationAndNonActiveProfile
()
throws
Exception
{
SpringApplication
application
=
new
SpringApplication
(
SpringApplication
application
=
new
SpringApplication
(
WithPropertySourceAndProfile
.
class
);
WithPropertySourceAndProfile
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
ConfigurableApplicationContext
context
=
application
.
run
();
ConfigurableApplicationContext
context
=
application
.
run
();
String
property
=
context
.
getEnvironment
().
getProperty
(
"my.property"
);
String
property
=
context
.
getEnvironment
().
getProperty
(
"my.property"
);
assertThat
(
property
).
isEqualTo
(
"fromapplicationproperties"
);
assertThat
(
property
).
isEqualTo
(
"fromapplicationproperties"
);
...
@@ -691,7 +692,7 @@ public class ConfigFileApplicationListenerTests {
...
@@ -691,7 +692,7 @@ public class ConfigFileApplicationListenerTests {
public
void
propertySourceAnnotationMultipleLocations
()
throws
Exception
{
public
void
propertySourceAnnotationMultipleLocations
()
throws
Exception
{
SpringApplication
application
=
new
SpringApplication
(
SpringApplication
application
=
new
SpringApplication
(
WithPropertySourceMultipleLocations
.
class
);
WithPropertySourceMultipleLocations
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
ConfigurableApplicationContext
context
=
application
.
run
();
ConfigurableApplicationContext
context
=
application
.
run
();
String
property
=
context
.
getEnvironment
().
getProperty
(
"the.property"
);
String
property
=
context
.
getEnvironment
().
getProperty
(
"the.property"
);
assertThat
(
property
).
isEqualTo
(
"frommorepropertiesfile"
);
assertThat
(
property
).
isEqualTo
(
"frommorepropertiesfile"
);
...
@@ -704,7 +705,7 @@ public class ConfigFileApplicationListenerTests {
...
@@ -704,7 +705,7 @@ public class ConfigFileApplicationListenerTests {
public
void
propertySourceAnnotationMultipleLocationsAndName
()
throws
Exception
{
public
void
propertySourceAnnotationMultipleLocationsAndName
()
throws
Exception
{
SpringApplication
application
=
new
SpringApplication
(
SpringApplication
application
=
new
SpringApplication
(
WithPropertySourceMultipleLocationsAndName
.
class
);
WithPropertySourceMultipleLocationsAndName
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
ConfigurableApplicationContext
context
=
application
.
run
();
ConfigurableApplicationContext
context
=
application
.
run
();
String
property
=
context
.
getEnvironment
().
getProperty
(
"the.property"
);
String
property
=
context
.
getEnvironment
().
getProperty
(
"the.property"
);
assertThat
(
property
).
isEqualTo
(
"frommorepropertiesfile"
);
assertThat
(
property
).
isEqualTo
(
"frommorepropertiesfile"
);
...
@@ -715,7 +716,7 @@ public class ConfigFileApplicationListenerTests {
...
@@ -715,7 +716,7 @@ public class ConfigFileApplicationListenerTests {
@Test
@Test
public
void
activateProfileFromProfileSpecificProperties
()
throws
Exception
{
public
void
activateProfileFromProfileSpecificProperties
()
throws
Exception
{
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
this
.
context
=
application
.
run
(
"--spring.profiles.active=includeprofile"
);
this
.
context
=
application
.
run
(
"--spring.profiles.active=includeprofile"
);
ConfigurableEnvironment
environment
=
this
.
context
.
getEnvironment
();
ConfigurableEnvironment
environment
=
this
.
context
.
getEnvironment
();
assertThat
(
environment
).
has
(
matchingProfile
(
"includeprofile"
));
assertThat
(
environment
).
has
(
matchingProfile
(
"includeprofile"
));
...
@@ -729,7 +730,7 @@ public class ConfigFileApplicationListenerTests {
...
@@ -729,7 +730,7 @@ public class ConfigFileApplicationListenerTests {
public
void
profileSubDocumentInSameProfileSpecificFile
()
throws
Exception
{
public
void
profileSubDocumentInSameProfileSpecificFile
()
throws
Exception
{
// gh-340
// gh-340
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
this
.
context
=
application
this
.
context
=
application
.
run
(
"--spring.profiles.active=activeprofilewithsubdoc"
);
.
run
(
"--spring.profiles.active=activeprofilewithsubdoc"
);
String
property
=
this
.
context
.
getEnvironment
().
getProperty
(
"foobar"
);
String
property
=
this
.
context
.
getEnvironment
().
getProperty
(
"foobar"
);
...
@@ -740,7 +741,7 @@ public class ConfigFileApplicationListenerTests {
...
@@ -740,7 +741,7 @@ public class ConfigFileApplicationListenerTests {
public
void
profileSubDocumentInDifferentProfileSpecificFile
()
throws
Exception
{
public
void
profileSubDocumentInDifferentProfileSpecificFile
()
throws
Exception
{
// gh-4132
// gh-4132
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
this
.
context
=
application
.
run
(
this
.
context
=
application
.
run
(
"--spring.profiles.active=activeprofilewithdifferentsubdoc,activeprofilewithdifferentsubdoc2"
);
"--spring.profiles.active=activeprofilewithdifferentsubdoc,activeprofilewithdifferentsubdoc2"
);
String
property
=
this
.
context
.
getEnvironment
().
getProperty
(
"foobar"
);
String
property
=
this
.
context
.
getEnvironment
().
getProperty
(
"foobar"
);
...
@@ -762,7 +763,7 @@ public class ConfigFileApplicationListenerTests {
...
@@ -762,7 +763,7 @@ public class ConfigFileApplicationListenerTests {
@Test
@Test
public
void
customDefaultProfile
()
throws
Exception
{
public
void
customDefaultProfile
()
throws
Exception
{
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
this
.
context
=
application
.
run
(
"--spring.profiles.default=customdefault"
);
this
.
context
=
application
.
run
(
"--spring.profiles.default=customdefault"
);
String
property
=
this
.
context
.
getEnvironment
().
getProperty
(
"customdefault"
);
String
property
=
this
.
context
.
getEnvironment
().
getProperty
(
"customdefault"
);
assertThat
(
property
).
isEqualTo
(
"true"
);
assertThat
(
property
).
isEqualTo
(
"true"
);
...
@@ -771,7 +772,7 @@ public class ConfigFileApplicationListenerTests {
...
@@ -771,7 +772,7 @@ public class ConfigFileApplicationListenerTests {
@Test
@Test
public
void
customDefaultProfileAndActive
()
throws
Exception
{
public
void
customDefaultProfileAndActive
()
throws
Exception
{
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
this
.
context
=
application
.
run
(
"--spring.profiles.default=customdefault"
,
this
.
context
=
application
.
run
(
"--spring.profiles.default=customdefault"
,
"--spring.profiles.active=dev"
);
"--spring.profiles.active=dev"
);
String
property
=
this
.
context
.
getEnvironment
().
getProperty
(
"my.property"
);
String
property
=
this
.
context
.
getEnvironment
().
getProperty
(
"my.property"
);
...
@@ -784,7 +785,7 @@ public class ConfigFileApplicationListenerTests {
...
@@ -784,7 +785,7 @@ public class ConfigFileApplicationListenerTests {
public
void
customDefaultProfileAndActiveFromFile
()
throws
Exception
{
public
void
customDefaultProfileAndActiveFromFile
()
throws
Exception
{
// gh-5998
// gh-5998
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
this
.
context
=
application
.
run
(
"--spring.config.name=customprofile"
,
this
.
context
=
application
.
run
(
"--spring.config.name=customprofile"
,
"--spring.profiles.default=customdefault"
);
"--spring.profiles.default=customdefault"
);
ConfigurableEnvironment
environment
=
this
.
context
.
getEnvironment
();
ConfigurableEnvironment
environment
=
this
.
context
.
getEnvironment
();
...
@@ -797,7 +798,7 @@ public class ConfigFileApplicationListenerTests {
...
@@ -797,7 +798,7 @@ public class ConfigFileApplicationListenerTests {
@Test
@Test
public
void
additionalProfilesCanBeIncludedFromAnyPropertySource
()
throws
Exception
{
public
void
additionalProfilesCanBeIncludedFromAnyPropertySource
()
throws
Exception
{
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
this
.
context
=
application
.
run
(
"--spring.profiles.active=myprofile"
,
this
.
context
=
application
.
run
(
"--spring.profiles.active=myprofile"
,
"--spring.profiles.include=dev"
);
"--spring.profiles.include=dev"
);
String
property
=
this
.
context
.
getEnvironment
().
getProperty
(
"my.property"
);
String
property
=
this
.
context
.
getEnvironment
().
getProperty
(
"my.property"
);
...
...
spring-boot/src/test/java/org/springframework/boot/diagnostics/FailureAnalyzersIntegrationTests.java
View file @
95f659f4
/*
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
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.
...
@@ -21,6 +21,7 @@ import javax.annotation.PostConstruct;
...
@@ -21,6 +21,7 @@ import javax.annotation.PostConstruct;
import
org.junit.Rule
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.springframework.boot.WebApplicationType
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.boot.context.embedded.PortInUseException
;
import
org.springframework.boot.context.embedded.PortInUseException
;
import
org.springframework.boot.testutil.InternalOutputCapture
;
import
org.springframework.boot.testutil.InternalOutputCapture
;
...
@@ -42,7 +43,8 @@ public class FailureAnalyzersIntegrationTests {
...
@@ -42,7 +43,8 @@ public class FailureAnalyzersIntegrationTests {
@Test
@Test
public
void
analysisIsPerformed
()
{
public
void
analysisIsPerformed
()
{
try
{
try
{
new
SpringApplicationBuilder
(
TestConfiguration
.
class
).
web
(
false
).
run
();
new
SpringApplicationBuilder
(
TestConfiguration
.
class
).
web
(
WebApplicationType
.
NONE
)
.
run
();
fail
(
"Application started successfully"
);
fail
(
"Application started successfully"
);
}
}
catch
(
Exception
ex
)
{
catch
(
Exception
ex
)
{
...
...
spring-boot/src/test/java/org/springframework/boot/liquibase/LiquibaseServiceLocatorApplicationListenerTests.java
View file @
95f659f4
/*
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
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.
...
@@ -23,6 +23,7 @@ import org.junit.After;
...
@@ -23,6 +23,7 @@ import org.junit.After;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.WebApplicationType
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.util.ReflectionUtils
;
import
org.springframework.util.ReflectionUtils
;
...
@@ -48,7 +49,7 @@ public class LiquibaseServiceLocatorApplicationListenerTests {
...
@@ -48,7 +49,7 @@ public class LiquibaseServiceLocatorApplicationListenerTests {
@Test
@Test
public
void
replacesServiceLocator
()
throws
Exception
{
public
void
replacesServiceLocator
()
throws
Exception
{
SpringApplication
application
=
new
SpringApplication
(
Conf
.
class
);
SpringApplication
application
=
new
SpringApplication
(
Conf
.
class
);
application
.
setWeb
Environment
(
false
);
application
.
setWeb
ApplicationType
(
WebApplicationType
.
NONE
);
this
.
context
=
application
.
run
();
this
.
context
=
application
.
run
();
ServiceLocator
instance
=
ServiceLocator
.
getInstance
();
ServiceLocator
instance
=
ServiceLocator
.
getInstance
();
Field
field
=
ReflectionUtils
.
findField
(
ServiceLocator
.
class
,
"classResolver"
);
Field
field
=
ReflectionUtils
.
findField
(
ServiceLocator
.
class
,
"classResolver"
);
...
...
spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerIntegrationTests.java
View file @
95f659f4
/*
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
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.
...
@@ -21,6 +21,7 @@ import org.junit.Test;
...
@@ -21,6 +21,7 @@ import org.junit.Test;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.boot.WebApplicationType
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.boot.context.event.ApplicationStartingEvent
;
import
org.springframework.boot.context.event.ApplicationStartingEvent
;
import
org.springframework.boot.testutil.InternalOutputCapture
;
import
org.springframework.boot.testutil.InternalOutputCapture
;
...
@@ -43,7 +44,7 @@ public class LoggingApplicationListenerIntegrationTests {
...
@@ -43,7 +44,7 @@ public class LoggingApplicationListenerIntegrationTests {
@Test
@Test
public
void
loggingSystemRegisteredInTheContext
()
{
public
void
loggingSystemRegisteredInTheContext
()
{
ConfigurableApplicationContext
context
=
new
SpringApplicationBuilder
(
ConfigurableApplicationContext
context
=
new
SpringApplicationBuilder
(
SampleService
.
class
).
web
(
false
).
run
();
SampleService
.
class
).
web
(
WebApplicationType
.
NONE
).
run
();
try
{
try
{
SampleService
service
=
context
.
getBean
(
SampleService
.
class
);
SampleService
service
=
context
.
getBean
(
SampleService
.
class
);
assertThat
(
service
.
loggingSystem
).
isNotNull
();
assertThat
(
service
.
loggingSystem
).
isNotNull
();
...
@@ -55,8 +56,8 @@ public class LoggingApplicationListenerIntegrationTests {
...
@@ -55,8 +56,8 @@ public class LoggingApplicationListenerIntegrationTests {
@Test
@Test
public
void
loggingPerformedDuringChildApplicationStartIsNotLost
()
{
public
void
loggingPerformedDuringChildApplicationStartIsNotLost
()
{
new
SpringApplicationBuilder
(
Config
.
class
).
web
(
false
).
child
(
Config
.
class
)
new
SpringApplicationBuilder
(
Config
.
class
).
web
(
WebApplicationType
.
NONE
)
.
web
(
false
)
.
child
(
Config
.
class
).
web
(
WebApplicationType
.
NONE
)
.
listeners
(
new
ApplicationListener
<
ApplicationStartingEvent
>()
{
.
listeners
(
new
ApplicationListener
<
ApplicationStartingEvent
>()
{
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
getClass
());
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
getClass
());
...
...
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