Add new WebApplicationType enum to pave the way for Web Flux support
Closes gh-8077
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* 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.
|
||||
@@ -22,6 +22,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.test.util.ApplicationContextTestUtils;
|
||||
@@ -50,7 +51,7 @@ public class ShutdownParentEndpointTests {
|
||||
@Test
|
||||
public void shutdownChild() throws Exception {
|
||||
this.context = new SpringApplicationBuilder(Config.class).child(Empty.class)
|
||||
.web(false).run();
|
||||
.web(WebApplicationType.NONE).run();
|
||||
CountDownLatch latch = this.context.getBean(Config.class).latch;
|
||||
assertThat((String) getEndpointBean().invoke().get("message"))
|
||||
.startsWith("Shutting down");
|
||||
@@ -61,7 +62,7 @@ public class ShutdownParentEndpointTests {
|
||||
@Test
|
||||
public void shutdownParent() throws Exception {
|
||||
this.context = new SpringApplicationBuilder(Empty.class).child(Config.class)
|
||||
.web(false).run();
|
||||
.web(WebApplicationType.NONE).run();
|
||||
CountDownLatch latch = this.context.getBean(Config.class).latch;
|
||||
assertThat((String) getEndpointBean().invoke().get("message"))
|
||||
.startsWith("Shutting down");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* 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.
|
||||
@@ -32,6 +32,7 @@ import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactoryUtils;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.admin.SpringApplicationAdminMXBeanRegistrar;
|
||||
import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration;
|
||||
@@ -136,13 +137,13 @@ public class SpringApplicationAdminJmxAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void onlyRegisteredOnceWhenThereIsAChildContext() throws Exception {
|
||||
SpringApplicationBuilder parentBuilder = new SpringApplicationBuilder().web(false)
|
||||
.sources(JmxAutoConfiguration.class,
|
||||
SpringApplicationBuilder parentBuilder = new SpringApplicationBuilder()
|
||||
.web(WebApplicationType.NONE).sources(JmxAutoConfiguration.class,
|
||||
SpringApplicationAdminJmxAutoConfiguration.class);
|
||||
SpringApplicationBuilder childBuilder = parentBuilder
|
||||
.child(JmxAutoConfiguration.class,
|
||||
SpringApplicationAdminJmxAutoConfiguration.class)
|
||||
.web(false);
|
||||
.web(WebApplicationType.NONE);
|
||||
ConfigurableApplicationContext parent = null;
|
||||
ConfigurableApplicationContext child = null;
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.security.oauth2.OAuth2ClientProperties;
|
||||
import org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2RestOperationsConfiguration;
|
||||
@@ -86,7 +87,7 @@ public class ResourceServerTokenServicesConfigurationTests {
|
||||
@Test
|
||||
public void defaultIsRemoteTokenServices() {
|
||||
this.context = new SpringApplicationBuilder(ResourceConfiguration.class)
|
||||
.web(false).run();
|
||||
.web(WebApplicationType.NONE).run();
|
||||
RemoteTokenServices services = this.context.getBean(RemoteTokenServices.class);
|
||||
assertThat(services).isNotNull();
|
||||
}
|
||||
@@ -97,7 +98,7 @@ public class ResourceServerTokenServicesConfigurationTests {
|
||||
"security.oauth2.resource.tokenInfoUri:http://example.com",
|
||||
"security.oauth2.resource.clientId=acme");
|
||||
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);
|
||||
assertThat(services).isNotNull();
|
||||
}
|
||||
@@ -107,7 +108,7 @@ public class ResourceServerTokenServicesConfigurationTests {
|
||||
EnvironmentTestUtils.addEnvironment(this.environment,
|
||||
"security.oauth2.resource.userInfoUri:http://example.com");
|
||||
this.context = new SpringApplicationBuilder(ResourceConfiguration.class)
|
||||
.environment(this.environment).web(false).run();
|
||||
.environment(this.environment).web(WebApplicationType.NONE).run();
|
||||
UserInfoTokenServices services = this.context
|
||||
.getBean(UserInfoTokenServices.class);
|
||||
assertThat(services).isNotNull();
|
||||
@@ -118,7 +119,7 @@ public class ResourceServerTokenServicesConfigurationTests {
|
||||
EnvironmentTestUtils.addEnvironment(this.environment,
|
||||
"security.oauth2.resource.userInfoUri:http://example.com");
|
||||
this.context = new SpringApplicationBuilder(AuthoritiesConfiguration.class)
|
||||
.environment(this.environment).web(false).run();
|
||||
.environment(this.environment).web(WebApplicationType.NONE).run();
|
||||
UserInfoTokenServices services = this.context
|
||||
.getBean(UserInfoTokenServices.class);
|
||||
assertThat(services).isNotNull();
|
||||
@@ -131,7 +132,7 @@ public class ResourceServerTokenServicesConfigurationTests {
|
||||
EnvironmentTestUtils.addEnvironment(this.environment,
|
||||
"security.oauth2.resource.userInfoUri:http://example.com");
|
||||
this.context = new SpringApplicationBuilder(PrincipalConfiguration.class)
|
||||
.environment(this.environment).web(false).run();
|
||||
.environment(this.environment).web(WebApplicationType.NONE).run();
|
||||
UserInfoTokenServices services = this.context
|
||||
.getBean(UserInfoTokenServices.class);
|
||||
assertThat(services).isNotNull();
|
||||
@@ -146,7 +147,7 @@ public class ResourceServerTokenServicesConfigurationTests {
|
||||
"security.oauth2.resource.userInfoUri:http://example.com",
|
||||
"server.port=-1", "debug=true");
|
||||
this.context = new SpringApplicationBuilder(ResourceNoClientConfiguration.class)
|
||||
.environment(this.environment).web(true).run();
|
||||
.environment(this.environment).web(WebApplicationType.SERVLET).run();
|
||||
BeanDefinition bean = ((BeanDefinitionRegistry) this.context)
|
||||
.getBeanDefinition("scopedTarget.oauth2ClientContext");
|
||||
assertThat(bean.getScope()).isEqualTo("request");
|
||||
@@ -159,7 +160,7 @@ public class ResourceServerTokenServicesConfigurationTests {
|
||||
"security.oauth2.resource.tokenInfoUri:http://example.com",
|
||||
"security.oauth2.resource.preferTokenInfo:false");
|
||||
this.context = new SpringApplicationBuilder(ResourceConfiguration.class)
|
||||
.environment(this.environment).web(false).run();
|
||||
.environment(this.environment).web(WebApplicationType.NONE).run();
|
||||
UserInfoTokenServices services = this.context
|
||||
.getBean(UserInfoTokenServices.class);
|
||||
assertThat(services).isNotNull();
|
||||
@@ -172,7 +173,8 @@ public class ResourceServerTokenServicesConfigurationTests {
|
||||
"security.oauth2.resource.tokenInfoUri:http://example.com",
|
||||
"security.oauth2.resource.preferTokenInfo:false");
|
||||
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
|
||||
.getBean(UserInfoTokenServices.class);
|
||||
assertThat(services).isNotNull();
|
||||
@@ -183,7 +185,7 @@ public class ResourceServerTokenServicesConfigurationTests {
|
||||
EnvironmentTestUtils.addEnvironment(this.environment,
|
||||
"security.oauth2.resource.jwt.keyValue=FOOBAR");
|
||||
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);
|
||||
assertThat(services).isNotNull();
|
||||
}
|
||||
@@ -193,7 +195,7 @@ public class ResourceServerTokenServicesConfigurationTests {
|
||||
EnvironmentTestUtils.addEnvironment(this.environment,
|
||||
"security.oauth2.resource.jwt.keyValue=" + PUBLIC_KEY);
|
||||
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);
|
||||
assertThat(services).isNotNull();
|
||||
}
|
||||
@@ -205,7 +207,7 @@ public class ResourceServerTokenServicesConfigurationTests {
|
||||
"spring.social.facebook.app-id=foo",
|
||||
"spring.social.facebook.app-secret=bar");
|
||||
this.context = new SpringApplicationBuilder(SocialResourceConfiguration.class)
|
||||
.environment(this.environment).web(true).run();
|
||||
.environment(this.environment).web(WebApplicationType.SERVLET).run();
|
||||
ConnectionFactoryLocator connectionFactory = this.context
|
||||
.getBean(ConnectionFactoryLocator.class);
|
||||
assertThat(connectionFactory).isNotNull();
|
||||
@@ -220,7 +222,7 @@ public class ResourceServerTokenServicesConfigurationTests {
|
||||
"security.oauth2.resource.userInfoUri:http://example.com");
|
||||
this.context = new SpringApplicationBuilder(
|
||||
CustomUserInfoRestTemplateFactory.class, ResourceConfiguration.class)
|
||||
.environment(this.environment).web(false).run();
|
||||
.environment(this.environment).web(WebApplicationType.NONE).run();
|
||||
assertThat(this.context.getBeansOfType(UserInfoRestTemplateFactory.class))
|
||||
.hasSize(1);
|
||||
assertThat(this.context.getBean(UserInfoRestTemplateFactory.class))
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* 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.
|
||||
@@ -23,6 +23,7 @@ import java.util.List;
|
||||
import org.springframework.boot.Banner;
|
||||
import org.springframework.boot.ResourceBanner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.context.config.AnsiOutputApplicationListener;
|
||||
import org.springframework.boot.context.config.ConfigFileApplicationListener;
|
||||
import org.springframework.boot.devtools.remote.client.RemoteClientConfiguration;
|
||||
@@ -55,7 +56,7 @@ public final class RemoteSpringApplication {
|
||||
Restarter.initialize(args, RestartInitializer.NONE);
|
||||
SpringApplication application = new SpringApplication(
|
||||
RemoteClientConfiguration.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
application.setBanner(getBanner());
|
||||
application.setInitializers(getInitializers());
|
||||
application.setListeners(getListeners());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* 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.
|
||||
@@ -24,6 +24,7 @@ import org.junit.rules.ExpectedException;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@@ -85,7 +86,7 @@ public class RemoteUrlPropertyExtractorTests {
|
||||
|
||||
private ApplicationContext doTest(String... args) {
|
||||
SpringApplication application = new SpringApplication(Config.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
application.addListeners(new RemoteUrlPropertyExtractor());
|
||||
return application.run(args);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* 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.
|
||||
@@ -27,6 +27,7 @@ import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.devtools.restart.RestartInitializer;
|
||||
import org.springframework.boot.devtools.restart.Restarter;
|
||||
@@ -63,7 +64,7 @@ public class DevToolPropertiesIntegrationTests {
|
||||
public void classPropertyConditionIsAffectedByDevToolProperties() {
|
||||
SpringApplication application = new SpringApplication(
|
||||
ClassConditionConfiguration.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run();
|
||||
this.context.getBean(ClassConditionConfiguration.class);
|
||||
}
|
||||
@@ -72,7 +73,7 @@ public class DevToolPropertiesIntegrationTests {
|
||||
public void beanMethodPropertyConditionIsAffectedByDevToolProperties() {
|
||||
SpringApplication application = new SpringApplication(
|
||||
BeanConditionConfiguration.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run();
|
||||
this.context.getBean(MyBean.class);
|
||||
}
|
||||
@@ -84,7 +85,7 @@ public class DevToolPropertiesIntegrationTests {
|
||||
Restarter.disable();
|
||||
SpringApplication application = new SpringApplication(
|
||||
BeanConditionConfiguration.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run();
|
||||
this.thrown.expect(NoSuchBeanDefinitionException.class);
|
||||
this.context.getBean(MyBean.class);
|
||||
@@ -97,7 +98,7 @@ public class DevToolPropertiesIntegrationTests {
|
||||
Restarter.disable();
|
||||
SpringApplication application = new SpringApplication(
|
||||
BeanConditionConfiguration.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
application.setDefaultProperties(Collections.<String, Object>singletonMap(
|
||||
"spring.devtools.remote.secret", "donttell"));
|
||||
this.context = application.run();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* 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.
|
||||
@@ -21,6 +21,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -54,7 +55,7 @@ public class RestartScopeInitializerTests {
|
||||
|
||||
private ConfigurableApplicationContext runApplication() {
|
||||
SpringApplication application = new SpringApplication(Config.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
return application.run();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* 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.
|
||||
@@ -22,6 +22,7 @@ import javax.ws.rs.Produces;
|
||||
|
||||
import com.sun.jersey.spi.container.servlet.ServletContainer;
|
||||
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
|
||||
@@ -54,7 +55,8 @@ public class SampleJersey1Application {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new SpringApplicationBuilder(SampleJersey1Application.class).web(true).run(args);
|
||||
new SpringApplicationBuilder(SampleJersey1Application.class)
|
||||
.web(WebApplicationType.SERVLET).run(args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* 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.
|
||||
@@ -20,6 +20,7 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
|
||||
import org.springframework.boot.test.rule.OutputCapture;
|
||||
@@ -59,7 +60,7 @@ public class SpringBootDependencyInjectionTestExecutionListenerTests {
|
||||
TestContext testContext = mock(TestContext.class);
|
||||
given(testContext.getTestInstance()).willThrow(new IllegalStateException());
|
||||
SpringApplication application = new SpringApplication(Config.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
ConfigurableApplicationContext applicationContext = application.run();
|
||||
given(testContext.getApplicationContext()).willReturn(applicationContext);
|
||||
try {
|
||||
|
||||
@@ -26,6 +26,7 @@ import java.util.Set;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.bind.RelaxedPropertyResolver;
|
||||
import org.springframework.boot.test.mock.web.SpringBootMockServletContext;
|
||||
import org.springframework.boot.test.util.EnvironmentTestUtils;
|
||||
@@ -108,13 +109,13 @@ public class SpringBootContextLoader extends AbstractContextLoader {
|
||||
List<ApplicationContextInitializer<?>> initializers = getInitializers(config,
|
||||
application);
|
||||
if (config instanceof WebMergedContextConfiguration) {
|
||||
application.setWebEnvironment(true);
|
||||
application.setWebApplicationType(WebApplicationType.SERVLET);
|
||||
if (!isEmbeddedWebEnvironment(config)) {
|
||||
new WebConfigurer().configure(config, application, initializers);
|
||||
}
|
||||
}
|
||||
else {
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
}
|
||||
application.setInitializers(initializers);
|
||||
ConfigurableApplicationContext context = application.run();
|
||||
|
||||
@@ -222,7 +222,7 @@ public class SpringApplication {
|
||||
|
||||
private Class<? extends ConfigurableApplicationContext> applicationContextClass;
|
||||
|
||||
private boolean webEnvironment;
|
||||
private WebApplicationType webApplicationType;
|
||||
|
||||
private boolean headless = true;
|
||||
|
||||
@@ -269,20 +269,20 @@ public class SpringApplication {
|
||||
if (sources != null && sources.length > 0) {
|
||||
this.sources.addAll(Arrays.asList(sources));
|
||||
}
|
||||
this.webEnvironment = deduceWebEnvironment();
|
||||
this.webApplicationType = deduceWebApplication();
|
||||
setInitializers((Collection) getSpringFactoriesInstances(
|
||||
ApplicationContextInitializer.class));
|
||||
setListeners((Collection) getSpringFactoriesInstances(ApplicationListener.class));
|
||||
this.mainApplicationClass = deduceMainApplicationClass();
|
||||
}
|
||||
|
||||
private boolean deduceWebEnvironment() {
|
||||
private WebApplicationType deduceWebApplication() {
|
||||
for (String className : WEB_ENVIRONMENT_CLASSES) {
|
||||
if (!ClassUtils.isPresent(className, null)) {
|
||||
return false;
|
||||
return WebApplicationType.NONE;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return WebApplicationType.SERVLET;
|
||||
}
|
||||
|
||||
private Class<?> deduceMainApplicationClass() {
|
||||
@@ -349,7 +349,8 @@ public class SpringApplication {
|
||||
ConfigurableEnvironment environment = getOrCreateEnvironment();
|
||||
configureEnvironment(environment, applicationArguments.getSourceArgs());
|
||||
listeners.environmentPrepared(environment);
|
||||
if (isWebEnvironment(environment) && !this.webEnvironment) {
|
||||
if (isWebEnvironment(environment)
|
||||
&& this.webApplicationType == WebApplicationType.NONE) {
|
||||
environment = convertToStandardEnvironment(environment);
|
||||
}
|
||||
return environment;
|
||||
@@ -446,7 +447,7 @@ public class SpringApplication {
|
||||
if (this.environment != null) {
|
||||
return this.environment;
|
||||
}
|
||||
if (this.webEnvironment) {
|
||||
if (this.webApplicationType == WebApplicationType.SERVLET) {
|
||||
return new StandardServletEnvironment();
|
||||
}
|
||||
return new StandardEnvironment();
|
||||
@@ -566,7 +567,8 @@ public class SpringApplication {
|
||||
* @param environment the environment to bind
|
||||
*/
|
||||
protected void bindToSpringApplication(ConfigurableEnvironment environment) {
|
||||
PropertiesConfigurationFactory<SpringApplication> binder = new PropertiesConfigurationFactory<>(this);
|
||||
PropertiesConfigurationFactory<SpringApplication> binder = new PropertiesConfigurationFactory<>(
|
||||
this);
|
||||
ConversionService conversionService = new DefaultConversionService();
|
||||
binder.setTargetName("spring.main");
|
||||
binder.setConversionService(conversionService);
|
||||
@@ -604,8 +606,9 @@ public class SpringApplication {
|
||||
Class<?> contextClass = this.applicationContextClass;
|
||||
if (contextClass == null) {
|
||||
try {
|
||||
contextClass = Class.forName(this.webEnvironment
|
||||
? DEFAULT_WEB_CONTEXT_CLASS : DEFAULT_CONTEXT_CLASS);
|
||||
contextClass = Class
|
||||
.forName(this.webApplicationType == WebApplicationType.SERVLET
|
||||
? DEFAULT_WEB_CONTEXT_CLASS : DEFAULT_CONTEXT_CLASS);
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
throw new IllegalStateException(
|
||||
@@ -953,18 +956,44 @@ public class SpringApplication {
|
||||
* Returns whether this {@link SpringApplication} is running within a web environment.
|
||||
* @return {@code true} if running within a web environment, otherwise {@code false}.
|
||||
* @see #setWebEnvironment(boolean)
|
||||
* @deprecated since 2.0.0 in favor of {@link #getWebApplicationType()}
|
||||
*/
|
||||
@Deprecated
|
||||
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
|
||||
* attempt to deduce the environment based on the classpath.
|
||||
* @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) {
|
||||
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 {
|
||||
Class<? extends ConfigurableApplicationContext> applicationContextClass) {
|
||||
this.applicationContextClass = applicationContextClass;
|
||||
if (!isWebApplicationContext(applicationContextClass)) {
|
||||
this.webEnvironment = false;
|
||||
this.webApplicationType = WebApplicationType.NONE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* 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.
|
||||
@@ -30,6 +30,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import org.springframework.beans.factory.support.BeanNameGenerator;
|
||||
import org.springframework.boot.Banner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextInitializer;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
@@ -296,12 +297,26 @@ public class SpringApplicationBuilder {
|
||||
* classpath if not set).
|
||||
* @param webEnvironment the flag to set
|
||||
* @return the current builder
|
||||
* @deprecated since 2.0.0 in favour of {@link #web(WebApplicationType)}
|
||||
*/
|
||||
@Deprecated
|
||||
public SpringApplicationBuilder web(boolean webEnvironment) {
|
||||
this.application.setWebEnvironment(webEnvironment);
|
||||
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.
|
||||
* @param logStartupInfo the flag to set. Default true.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* 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.
|
||||
@@ -72,7 +72,7 @@ public class BannerTests {
|
||||
@Test
|
||||
public void testDefaultBanner() throws Exception {
|
||||
SpringApplication application = new SpringApplication(Config.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run();
|
||||
assertThat(this.out.toString()).contains(":: Spring Boot ::");
|
||||
}
|
||||
@@ -80,7 +80,7 @@ public class BannerTests {
|
||||
@Test
|
||||
public void testDefaultBannerInLog() throws Exception {
|
||||
SpringApplication application = new SpringApplication(Config.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run();
|
||||
assertThat(this.out.toString()).contains(":: Spring Boot ::");
|
||||
}
|
||||
@@ -88,7 +88,7 @@ public class BannerTests {
|
||||
@Test
|
||||
public void testCustomBanner() throws Exception {
|
||||
SpringApplication application = new SpringApplication(Config.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
application.setBanner(new DummyBanner());
|
||||
this.context = application.run();
|
||||
assertThat(this.out.toString()).contains("My Banner");
|
||||
@@ -97,7 +97,7 @@ public class BannerTests {
|
||||
@Test
|
||||
public void testBannerInContext() throws Exception {
|
||||
SpringApplication application = new SpringApplication(Config.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run();
|
||||
assertThat(this.context.containsBean("springBootBanner")).isTrue();
|
||||
}
|
||||
@@ -105,7 +105,7 @@ public class BannerTests {
|
||||
@Test
|
||||
public void testCustomBannerInContext() throws Exception {
|
||||
SpringApplication application = new SpringApplication(Config.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
Banner banner = mock(Banner.class);
|
||||
application.setBanner(banner);
|
||||
this.context = application.run();
|
||||
@@ -124,7 +124,7 @@ public class BannerTests {
|
||||
public void testDisableBannerInContext() throws Exception {
|
||||
SpringApplication application = new SpringApplication(Config.class);
|
||||
application.setBannerMode(Mode.OFF);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run();
|
||||
assertThat(this.context.containsBean("springBootBanner")).isFalse();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* 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.
|
||||
@@ -46,7 +46,7 @@ public class ReproTests {
|
||||
// gh-308
|
||||
SpringApplication application = new SpringApplication(Config.class);
|
||||
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run(
|
||||
"--spring.config.name=enableprofileviaapplicationproperties",
|
||||
"--spring.profiles.active=dev");
|
||||
@@ -58,7 +58,7 @@ public class ReproTests {
|
||||
public void activeProfilesWithYamlAndCommandLine() throws Exception {
|
||||
// gh-322, gh-342
|
||||
SpringApplication application = new SpringApplication(Config.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
String configName = "--spring.config.name=activeprofilerepro";
|
||||
this.context = application.run(configName, "--spring.profiles.active=B");
|
||||
assertVersionProperty(this.context, "B", "B");
|
||||
@@ -68,7 +68,7 @@ public class ReproTests {
|
||||
public void activeProfilesWithYamlOnly() throws Exception {
|
||||
// gh-322, gh-342
|
||||
SpringApplication application = new SpringApplication(Config.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
String configName = "--spring.config.name=activeprofilerepro";
|
||||
this.context = application.run(configName);
|
||||
assertVersionProperty(this.context, "B", "B");
|
||||
@@ -78,7 +78,7 @@ public class ReproTests {
|
||||
public void orderActiveProfilesWithYamlOnly() throws Exception {
|
||||
// gh-322, gh-342
|
||||
SpringApplication application = new SpringApplication(Config.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
String configName = "--spring.config.name=activeprofilerepro-ordered";
|
||||
this.context = application.run(configName);
|
||||
assertVersionProperty(this.context, "B", "A", "B");
|
||||
@@ -88,7 +88,7 @@ public class ReproTests {
|
||||
public void commandLineBeatsProfilesWithYaml() throws Exception {
|
||||
// gh-322, gh-342
|
||||
SpringApplication application = new SpringApplication(Config.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
String configName = "--spring.config.name=activeprofilerepro";
|
||||
this.context = application.run(configName, "--spring.profiles.active=C");
|
||||
assertVersionProperty(this.context, "C", "C");
|
||||
@@ -98,7 +98,7 @@ public class ReproTests {
|
||||
public void orderProfilesWithYaml() throws Exception {
|
||||
// gh-322, gh-342
|
||||
SpringApplication application = new SpringApplication(Config.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
String configName = "--spring.config.name=activeprofilerepro";
|
||||
this.context = application.run(configName, "--spring.profiles.active=A,C");
|
||||
assertVersionProperty(this.context, "C", "A", "C");
|
||||
@@ -108,7 +108,7 @@ public class ReproTests {
|
||||
public void reverseOrderOfProfilesWithYaml() throws Exception {
|
||||
// gh-322, gh-342
|
||||
SpringApplication application = new SpringApplication(Config.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
String configName = "--spring.config.name=activeprofilerepro";
|
||||
this.context = application.run(configName, "--spring.profiles.active=C,A");
|
||||
assertVersionProperty(this.context, "A", "C", "A");
|
||||
@@ -118,7 +118,7 @@ public class ReproTests {
|
||||
public void activeProfilesWithYamlAndCommandLineAndNoOverride() throws Exception {
|
||||
// gh-322, gh-342
|
||||
SpringApplication application = new SpringApplication(Config.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
String configName = "--spring.config.name=activeprofilerepro-without-override";
|
||||
this.context = application.run(configName, "--spring.profiles.active=B");
|
||||
assertVersionProperty(this.context, "B", "B");
|
||||
@@ -128,7 +128,7 @@ public class ReproTests {
|
||||
public void activeProfilesWithYamlOnlyAndNoOverride() throws Exception {
|
||||
// gh-322, gh-342
|
||||
SpringApplication application = new SpringApplication(Config.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
String configName = "--spring.config.name=activeprofilerepro-without-override";
|
||||
this.context = application.run(configName);
|
||||
assertVersionProperty(this.context, null);
|
||||
@@ -138,7 +138,7 @@ public class ReproTests {
|
||||
public void commandLineBeatsProfilesWithYamlAndNoOverride() throws Exception {
|
||||
// gh-322, gh-342
|
||||
SpringApplication application = new SpringApplication(Config.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
String configName = "--spring.config.name=activeprofilerepro-without-override";
|
||||
this.context = application.run(configName, "--spring.profiles.active=C");
|
||||
assertVersionProperty(this.context, "C", "C");
|
||||
@@ -148,7 +148,7 @@ public class ReproTests {
|
||||
public void orderProfilesWithYamlAndNoOverride() throws Exception {
|
||||
// gh-322, gh-342
|
||||
SpringApplication application = new SpringApplication(Config.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
String configName = "--spring.config.name=activeprofilerepro-without-override";
|
||||
this.context = application.run(configName, "--spring.profiles.active=A,C");
|
||||
assertVersionProperty(this.context, "C", "A", "C");
|
||||
@@ -158,7 +158,7 @@ public class ReproTests {
|
||||
public void reverseOrderOfProfilesWithYamlAndNoOverride() throws Exception {
|
||||
// gh-322, gh-342
|
||||
SpringApplication application = new SpringApplication(Config.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
String configName = "--spring.config.name=activeprofilerepro-without-override";
|
||||
this.context = application.run(configName, "--spring.profiles.active=C,A");
|
||||
assertVersionProperty(this.context, "A", "C", "A");
|
||||
|
||||
@@ -171,7 +171,7 @@ public class SpringApplicationTests {
|
||||
@Test
|
||||
public void customBanner() throws Exception {
|
||||
SpringApplication application = spy(new SpringApplication(ExampleConfig.class));
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run("--banner.location=classpath:test-banner.txt");
|
||||
assertThat(this.output.toString()).startsWith("Running a Test!");
|
||||
}
|
||||
@@ -179,7 +179,7 @@ public class SpringApplicationTests {
|
||||
@Test
|
||||
public void customBannerWithProperties() throws Exception {
|
||||
SpringApplication application = spy(new SpringApplication(ExampleConfig.class));
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run(
|
||||
"--banner.location=classpath:test-banner-with-placeholder.txt",
|
||||
"--test.property=123456");
|
||||
@@ -192,7 +192,7 @@ public class SpringApplicationTests {
|
||||
MockResourceLoader resourceLoader = new MockResourceLoader();
|
||||
resourceLoader.addResource("banner.gif", "black-and-white.gif");
|
||||
resourceLoader.addResource("banner.txt", "foobar.txt");
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
application.setResourceLoader(resourceLoader);
|
||||
application.run();
|
||||
assertThat(this.output.toString()).contains("@@@@").contains("Foo Bar");
|
||||
@@ -203,7 +203,7 @@ public class SpringApplicationTests {
|
||||
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
||||
MockResourceLoader resourceLoader = new MockResourceLoader();
|
||||
resourceLoader.addResource("banner.gif", "black-and-white.gif");
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
application.setResourceLoader(resourceLoader);
|
||||
application.run();
|
||||
assertThat(this.output.toString()).contains("@@@@@@");
|
||||
@@ -212,7 +212,7 @@ public class SpringApplicationTests {
|
||||
@Test
|
||||
public void logsNoActiveProfiles() throws Exception {
|
||||
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run();
|
||||
assertThat(this.output.toString()).contains(
|
||||
"No active profile set, falling back to default profiles: default");
|
||||
@@ -221,7 +221,7 @@ public class SpringApplicationTests {
|
||||
@Test
|
||||
public void logsActiveProfiles() throws Exception {
|
||||
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run("--spring.profiles.active=myprofiles");
|
||||
assertThat(this.output.toString())
|
||||
.contains("The following profiles are active: myprofile");
|
||||
@@ -230,7 +230,7 @@ public class SpringApplicationTests {
|
||||
@Test
|
||||
public void enableBannerInLogViaProperty() throws Exception {
|
||||
SpringApplication application = spy(new SpringApplication(ExampleConfig.class));
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run("--spring.main.banner-mode=log");
|
||||
verify(application, atLeastOnce()).setBannerMode(Banner.Mode.LOG);
|
||||
assertThat(this.output.toString()).contains("o.s.boot.SpringApplication");
|
||||
@@ -281,7 +281,7 @@ public class SpringApplicationTests {
|
||||
@Test
|
||||
public void customId() throws Exception {
|
||||
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run("--spring.application.name=foo");
|
||||
assertThat(this.context.getId()).startsWith("foo");
|
||||
}
|
||||
@@ -297,7 +297,7 @@ public class SpringApplicationTests {
|
||||
@Test
|
||||
public void specificApplicationContextInitializer() throws Exception {
|
||||
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
final AtomicReference<ApplicationContext> reference = new AtomicReference<ApplicationContext>();
|
||||
application.setInitializers(Arrays.asList(
|
||||
new ApplicationContextInitializer<ConfigurableApplicationContext>() {
|
||||
@@ -315,7 +315,7 @@ public class SpringApplicationTests {
|
||||
@Test
|
||||
public void applicationRunningEventListener() {
|
||||
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
final AtomicReference<SpringApplication> reference = new AtomicReference<SpringApplication>();
|
||||
class ApplicationReadyEventListener
|
||||
implements ApplicationListener<ApplicationReadyEvent> {
|
||||
@@ -334,7 +334,7 @@ public class SpringApplicationTests {
|
||||
@Test
|
||||
public void contextRefreshedEventListener() throws Exception {
|
||||
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
final AtomicReference<ApplicationContext> reference = new AtomicReference<ApplicationContext>();
|
||||
class InitializerListener implements ApplicationListener<ContextRefreshedEvent> {
|
||||
|
||||
@@ -355,7 +355,7 @@ public class SpringApplicationTests {
|
||||
@SuppressWarnings("deprecation")
|
||||
public void eventsOrder() {
|
||||
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
final List<ApplicationEvent> events = new ArrayList<ApplicationEvent>();
|
||||
class ApplicationRunningEventListener
|
||||
implements ApplicationListener<ApplicationEvent> {
|
||||
@@ -381,7 +381,7 @@ public class SpringApplicationTests {
|
||||
@Test
|
||||
public void defaultApplicationContext() throws Exception {
|
||||
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run();
|
||||
assertThat(this.context).isInstanceOf(AnnotationConfigApplicationContext.class);
|
||||
}
|
||||
@@ -389,7 +389,7 @@ public class SpringApplicationTests {
|
||||
@Test
|
||||
public void defaultApplicationContextForWeb() throws Exception {
|
||||
SpringApplication application = new SpringApplication(ExampleWebConfig.class);
|
||||
application.setWebEnvironment(true);
|
||||
application.setWebApplicationType(WebApplicationType.SERVLET);
|
||||
this.context = application.run();
|
||||
assertThat(this.context)
|
||||
.isInstanceOf(AnnotationConfigEmbeddedWebApplicationContext.class);
|
||||
@@ -399,7 +399,7 @@ public class SpringApplicationTests {
|
||||
public void customEnvironment() throws Exception {
|
||||
TestSpringApplication application = new TestSpringApplication(
|
||||
ExampleConfig.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
ConfigurableEnvironment environment = new StandardEnvironment();
|
||||
application.setEnvironment(environment);
|
||||
this.context = application.run();
|
||||
@@ -410,7 +410,7 @@ public class SpringApplicationTests {
|
||||
public void customResourceLoader() throws Exception {
|
||||
TestSpringApplication application = new TestSpringApplication(
|
||||
ExampleConfig.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
ResourceLoader resourceLoader = new DefaultResourceLoader();
|
||||
application.setResourceLoader(resourceLoader);
|
||||
this.context = application.run();
|
||||
@@ -443,7 +443,7 @@ public class SpringApplicationTests {
|
||||
public void customBeanNameGeneratorWithNonWebApplication() throws Exception {
|
||||
TestSpringApplication application = new TestSpringApplication(
|
||||
ExampleWebConfig.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
BeanNameGenerator beanNameGenerator = new DefaultBeanNameGenerator();
|
||||
application.setBeanNameGenerator(beanNameGenerator);
|
||||
this.context = application.run();
|
||||
@@ -456,7 +456,7 @@ public class SpringApplicationTests {
|
||||
@Test
|
||||
public void commandLinePropertySource() throws Exception {
|
||||
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
ConfigurableEnvironment environment = new StandardEnvironment();
|
||||
application.setEnvironment(environment);
|
||||
this.context = application.run("--foo=bar");
|
||||
@@ -467,7 +467,7 @@ public class SpringApplicationTests {
|
||||
@Test
|
||||
public void commandLinePropertySourceEnhancesEnvironment() throws Exception {
|
||||
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
ConfigurableEnvironment environment = new StandardEnvironment();
|
||||
environment.getPropertySources().addFirst(new MapPropertySource("commandLineArgs",
|
||||
Collections.<String, Object>singletonMap("foo", "original")));
|
||||
@@ -483,7 +483,7 @@ public class SpringApplicationTests {
|
||||
@Test
|
||||
public void propertiesFileEnhancesEnvironment() throws Exception {
|
||||
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
ConfigurableEnvironment environment = new StandardEnvironment();
|
||||
application.setEnvironment(environment);
|
||||
this.context = application.run();
|
||||
@@ -493,7 +493,7 @@ public class SpringApplicationTests {
|
||||
@Test
|
||||
public void addProfiles() throws Exception {
|
||||
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
application.setAdditionalProfiles("foo");
|
||||
ConfigurableEnvironment environment = new StandardEnvironment();
|
||||
application.setEnvironment(environment);
|
||||
@@ -504,7 +504,7 @@ public class SpringApplicationTests {
|
||||
@Test
|
||||
public void addProfilesOrder() throws Exception {
|
||||
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
application.setAdditionalProfiles("foo");
|
||||
ConfigurableEnvironment environment = new StandardEnvironment();
|
||||
application.setEnvironment(environment);
|
||||
@@ -516,7 +516,7 @@ public class SpringApplicationTests {
|
||||
@Test
|
||||
public void addProfilesOrderWithProperties() throws Exception {
|
||||
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
application.setAdditionalProfiles("other");
|
||||
ConfigurableEnvironment environment = new StandardEnvironment();
|
||||
application.setEnvironment(environment);
|
||||
@@ -529,7 +529,7 @@ public class SpringApplicationTests {
|
||||
@Test
|
||||
public void emptyCommandLinePropertySourceNotAdded() throws Exception {
|
||||
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
ConfigurableEnvironment environment = new StandardEnvironment();
|
||||
application.setEnvironment(environment);
|
||||
this.context = application.run();
|
||||
@@ -539,7 +539,7 @@ public class SpringApplicationTests {
|
||||
@Test
|
||||
public void disableCommandLinePropertySource() throws Exception {
|
||||
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
application.setAddCommandLineProperties(false);
|
||||
ConfigurableEnvironment environment = new StandardEnvironment();
|
||||
application.setEnvironment(environment);
|
||||
@@ -551,7 +551,7 @@ public class SpringApplicationTests {
|
||||
@Test
|
||||
public void runCommandLineRunnersAndApplicationRunners() throws Exception {
|
||||
SpringApplication application = new SpringApplication(CommandLineRunConfig.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run("arg");
|
||||
assertThat(this.context).has(runTestRunnerBean("runnerA"));
|
||||
assertThat(this.context).has(runTestRunnerBean("runnerB"));
|
||||
@@ -562,7 +562,7 @@ public class SpringApplicationTests {
|
||||
public void loadSources() throws Exception {
|
||||
Object[] sources = { ExampleConfig.class, "a", TestCommandLineRunner.class };
|
||||
TestSpringApplication application = new TestSpringApplication(sources);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
application.setUseMockLoader(true);
|
||||
this.context = application.run();
|
||||
Set<Object> initialSources = application.getSources();
|
||||
@@ -574,7 +574,7 @@ public class SpringApplicationTests {
|
||||
Object[] sources = {
|
||||
"classpath:org/springframework/boot/sample-${sample.app.test.prop}.xml" };
|
||||
TestSpringApplication application = new TestSpringApplication(sources);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run();
|
||||
}
|
||||
|
||||
@@ -594,7 +594,7 @@ public class SpringApplicationTests {
|
||||
@Test
|
||||
public void exit() throws Exception {
|
||||
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run();
|
||||
assertThat(this.context).isNotNull();
|
||||
assertThat(SpringApplication.exit(this.context)).isEqualTo(0);
|
||||
@@ -605,7 +605,7 @@ public class SpringApplicationTests {
|
||||
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
||||
ExitCodeListener listener = new ExitCodeListener();
|
||||
application.addListeners(listener);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run();
|
||||
assertThat(this.context).isNotNull();
|
||||
assertThat(SpringApplication.exit(this.context, new ExitCodeGenerator() {
|
||||
@@ -633,7 +633,7 @@ public class SpringApplicationTests {
|
||||
};
|
||||
ExitCodeListener listener = new ExitCodeListener();
|
||||
application.addListeners(listener);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
try {
|
||||
application.run();
|
||||
fail("Did not throw");
|
||||
@@ -658,7 +658,7 @@ public class SpringApplicationTests {
|
||||
};
|
||||
ExitCodeListener listener = new ExitCodeListener();
|
||||
application.addListeners(listener);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
try {
|
||||
application.run();
|
||||
fail("Did not throw");
|
||||
@@ -683,7 +683,7 @@ public class SpringApplicationTests {
|
||||
};
|
||||
ExitCodeListener listener = new ExitCodeListener();
|
||||
application.addListeners(listener);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
try {
|
||||
application.run();
|
||||
fail("Did not throw");
|
||||
@@ -703,7 +703,7 @@ public class SpringApplicationTests {
|
||||
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
||||
application.setDefaultProperties(StringUtils.splitArrayElementsIntoProperties(
|
||||
new String[] { "baz=", "bar=spam" }, "="));
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run("--bar=foo", "bucket", "crap");
|
||||
assertThat(this.context).isInstanceOf(AnnotationConfigApplicationContext.class);
|
||||
assertThat(getEnvironment().getProperty("bar")).isEqualTo("foo");
|
||||
@@ -714,7 +714,7 @@ public class SpringApplicationTests {
|
||||
public void commandLineArgsApplyToSpringApplication() throws Exception {
|
||||
TestSpringApplication application = new TestSpringApplication(
|
||||
ExampleConfig.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run("--spring.main.banner-mode=OFF");
|
||||
assertThat(application.getBannerMode()).isEqualTo(Banner.Mode.OFF);
|
||||
}
|
||||
@@ -792,7 +792,7 @@ public class SpringApplicationTests {
|
||||
public void headless() throws Exception {
|
||||
TestSpringApplication application = new TestSpringApplication(
|
||||
ExampleConfig.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run();
|
||||
assertThat(System.getProperty("java.awt.headless")).isEqualTo("true");
|
||||
}
|
||||
@@ -801,7 +801,7 @@ public class SpringApplicationTests {
|
||||
public void headlessFalse() throws Exception {
|
||||
TestSpringApplication application = new TestSpringApplication(
|
||||
ExampleConfig.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
application.setHeadless(false);
|
||||
this.context = application.run();
|
||||
assertThat(System.getProperty("java.awt.headless")).isEqualTo("false");
|
||||
@@ -812,7 +812,7 @@ public class SpringApplicationTests {
|
||||
System.setProperty("java.awt.headless", "false");
|
||||
TestSpringApplication application = new TestSpringApplication(
|
||||
ExampleConfig.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run();
|
||||
assertThat(System.getProperty("java.awt.headless")).isEqualTo("false");
|
||||
}
|
||||
@@ -821,7 +821,7 @@ public class SpringApplicationTests {
|
||||
public void getApplicationArgumentsBean() throws Exception {
|
||||
TestSpringApplication application = new TestSpringApplication(
|
||||
ExampleConfig.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run("--debug", "spring", "boot");
|
||||
ApplicationArguments args = this.context.getBean(ApplicationArguments.class);
|
||||
assertThat(args.getNonOptionArgs()).containsExactly("spring", "boot");
|
||||
@@ -829,7 +829,7 @@ public class SpringApplicationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void webEnvironmentSwitchedOffInListener() throws Exception {
|
||||
public void webApplicationSwitchedOffInListener() throws Exception {
|
||||
TestSpringApplication application = new TestSpringApplication(
|
||||
ExampleConfig.class);
|
||||
application.addListeners(
|
||||
@@ -842,7 +842,8 @@ public class SpringApplicationTests {
|
||||
.isInstanceOf(StandardServletEnvironment.class);
|
||||
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(
|
||||
event.getEnvironment(), "foo=bar");
|
||||
event.getSpringApplication().setWebEnvironment(false);
|
||||
event.getSpringApplication()
|
||||
.setWebApplicationType(WebApplicationType.NONE);
|
||||
}
|
||||
|
||||
});
|
||||
@@ -863,7 +864,7 @@ public class SpringApplicationTests {
|
||||
public void run() {
|
||||
SpringApplication application = new SpringApplication(
|
||||
FailingConfig.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
application.run();
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* 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.
|
||||
@@ -30,6 +30,7 @@ import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
@@ -74,7 +75,7 @@ public class SpringApplicationAdminMXBeanRegistrarTests {
|
||||
public void validateReadyFlag() {
|
||||
final ObjectName objectName = createObjectName(OBJECT_NAME);
|
||||
SpringApplication application = new SpringApplication(Config.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
application.addListeners(new ApplicationListener<ContextRefreshedEvent>() {
|
||||
@Override
|
||||
public void onApplicationEvent(ContextRefreshedEvent event) {
|
||||
@@ -114,7 +115,7 @@ public class SpringApplicationAdminMXBeanRegistrarTests {
|
||||
public void environmentIsExposed() {
|
||||
final ObjectName objectName = createObjectName(OBJECT_NAME);
|
||||
SpringApplication application = new SpringApplication(Config.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run("--foo.bar=blam");
|
||||
assertThat(isApplicationReady(objectName)).isTrue();
|
||||
assertThat(isApplicationEmbeddedWebApplication(objectName)).isFalse();
|
||||
@@ -126,7 +127,7 @@ public class SpringApplicationAdminMXBeanRegistrarTests {
|
||||
public void shutdownApp() throws InstanceNotFoundException {
|
||||
final ObjectName objectName = createObjectName(OBJECT_NAME);
|
||||
SpringApplication application = new SpringApplication(Config.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run();
|
||||
assertThat(this.context.isRunning()).isTrue();
|
||||
invokeShutdown(objectName);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* 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.
|
||||
@@ -22,6 +22,7 @@ import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.MapPropertySource;
|
||||
@@ -45,7 +46,7 @@ class SpringApplicationBindContextLoader extends AbstractContextLoader {
|
||||
throws Exception {
|
||||
SpringApplication application = new SpringApplication();
|
||||
application.setMainApplicationClass(config.getTestClass());
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
application.setSources(
|
||||
new LinkedHashSet<Object>(Arrays.asList(config.getClasses())));
|
||||
ConfigurableEnvironment environment = new StandardEnvironment();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* 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.
|
||||
@@ -24,6 +24,7 @@ import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextInitializer;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
@@ -203,7 +204,7 @@ public class SpringApplicationBuilderTests {
|
||||
public void parentFirstCreationWithProfileAndDefaultArgs() throws Exception {
|
||||
SpringApplicationBuilder application = new SpringApplicationBuilder(
|
||||
ExampleConfig.class).profiles("node").properties("transport=redis")
|
||||
.child(ChildConfig.class).web(false);
|
||||
.child(ChildConfig.class).web(WebApplicationType.NONE);
|
||||
this.context = application.run();
|
||||
assertThat(this.context.getEnvironment().acceptsProfiles("node")).isTrue();
|
||||
assertThat(this.context.getEnvironment().getProperty("transport"))
|
||||
@@ -220,7 +221,8 @@ public class SpringApplicationBuilderTests {
|
||||
public void parentFirstWithDifferentProfile() throws Exception {
|
||||
SpringApplicationBuilder application = new SpringApplicationBuilder(
|
||||
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();
|
||||
assertThat(this.context.getEnvironment().acceptsProfiles("node", "admin"))
|
||||
.isTrue();
|
||||
@@ -233,7 +235,7 @@ public class SpringApplicationBuilderTests {
|
||||
SpringApplicationBuilder shared = new SpringApplicationBuilder(
|
||||
ExampleConfig.class).profiles("node").properties("transport=redis");
|
||||
SpringApplicationBuilder application = shared.child(ChildConfig.class)
|
||||
.profiles("admin").web(false);
|
||||
.profiles("admin").web(WebApplicationType.NONE);
|
||||
shared.profiles("parent");
|
||||
this.context = application.run();
|
||||
assertThat(this.context.getEnvironment().acceptsProfiles("node", "admin"))
|
||||
@@ -249,7 +251,8 @@ public class SpringApplicationBuilderTests {
|
||||
SpringApplicationBuilder application = new SpringApplicationBuilder(
|
||||
ExampleConfig.class).environment(new StandardEnvironment())
|
||||
.profiles("node").properties("transport=redis")
|
||||
.child(ChildConfig.class).profiles("admin").web(false);
|
||||
.child(ChildConfig.class).profiles("admin")
|
||||
.web(WebApplicationType.NONE);
|
||||
this.context = application.run();
|
||||
assertThat(this.context.getEnvironment().acceptsProfiles("node", "admin"))
|
||||
.isTrue();
|
||||
@@ -273,7 +276,7 @@ public class SpringApplicationBuilderTests {
|
||||
@Test
|
||||
public void initializersCreatedOnce() throws Exception {
|
||||
SpringApplicationBuilder application = new SpringApplicationBuilder(
|
||||
ExampleConfig.class).web(false);
|
||||
ExampleConfig.class).web(WebApplicationType.NONE);
|
||||
this.context = application.run();
|
||||
assertThat(application.application().getInitializers()).hasSize(4);
|
||||
}
|
||||
@@ -281,7 +284,7 @@ public class SpringApplicationBuilderTests {
|
||||
@Test
|
||||
public void initializersCreatedOnceForChild() throws Exception {
|
||||
SpringApplicationBuilder application = new SpringApplicationBuilder(
|
||||
ExampleConfig.class).child(ChildConfig.class).web(false);
|
||||
ExampleConfig.class).child(ChildConfig.class).web(WebApplicationType.NONE);
|
||||
this.context = application.run();
|
||||
assertThat(application.application().getInitializers()).hasSize(5);
|
||||
}
|
||||
@@ -289,7 +292,7 @@ public class SpringApplicationBuilderTests {
|
||||
@Test
|
||||
public void initializersIncludeDefaults() throws Exception {
|
||||
SpringApplicationBuilder application = new SpringApplicationBuilder(
|
||||
ExampleConfig.class).web(false).initializers(
|
||||
ExampleConfig.class).web(WebApplicationType.NONE).initializers(
|
||||
new ApplicationContextInitializer<ConfigurableApplicationContext>() {
|
||||
@Override
|
||||
public void initialize(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* 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.
|
||||
@@ -24,6 +24,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.ansi.AnsiOutput;
|
||||
import org.springframework.boot.ansi.AnsiOutput.Enabled;
|
||||
import org.springframework.boot.ansi.AnsiOutputEnabledValue;
|
||||
@@ -60,7 +61,7 @@ public class AnsiOutputApplicationListenerTests {
|
||||
@Test
|
||||
public void enabled() {
|
||||
SpringApplication application = new SpringApplication(Config.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
Map<String, Object> props = new HashMap<String, Object>();
|
||||
props.put("spring.output.ansi.enabled", "ALWAYS");
|
||||
application.setDefaultProperties(props);
|
||||
@@ -71,7 +72,7 @@ public class AnsiOutputApplicationListenerTests {
|
||||
@Test
|
||||
public void disabled() throws Exception {
|
||||
SpringApplication application = new SpringApplication(Config.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
Map<String, Object> props = new HashMap<String, Object>();
|
||||
props.put("spring.output.ansi.enabled", "never");
|
||||
application.setDefaultProperties(props);
|
||||
@@ -85,8 +86,8 @@ public class AnsiOutputApplicationListenerTests {
|
||||
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(environment,
|
||||
"spring.config.name=ansi");
|
||||
SpringApplication application = new SpringApplication(Config.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setEnvironment(environment);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run();
|
||||
assertThat(AnsiOutputEnabledValue.get()).isEqualTo(Enabled.NEVER);
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.beans.CachedIntrospectionResults;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.context.config.ConfigFileApplicationListener.ConfigurationPropertySources;
|
||||
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
|
||||
import org.springframework.boot.context.event.ApplicationPreparedEvent;
|
||||
@@ -619,7 +620,7 @@ public class ConfigFileApplicationListenerTests {
|
||||
@Test
|
||||
public void propertySourceAnnotation() throws Exception {
|
||||
SpringApplication application = new SpringApplication(WithPropertySource.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
ConfigurableApplicationContext context = application.run();
|
||||
String property = context.getEnvironment().getProperty("the.property");
|
||||
assertThat(property).isEqualTo("fromspecificlocation");
|
||||
@@ -637,7 +638,7 @@ public class ConfigFileApplicationListenerTests {
|
||||
SpringApplication application = new SpringApplication(
|
||||
WithPropertySourcePlaceholders.class);
|
||||
application.setEnvironment(this.environment);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
ConfigurableApplicationContext context = application.run();
|
||||
String property = context.getEnvironment().getProperty("the.property");
|
||||
assertThat(property).isEqualTo("fromspecificlocation");
|
||||
@@ -650,7 +651,7 @@ public class ConfigFileApplicationListenerTests {
|
||||
public void propertySourceAnnotationWithName() throws Exception {
|
||||
SpringApplication application = new SpringApplication(
|
||||
WithPropertySourceAndName.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
ConfigurableApplicationContext context = application.run();
|
||||
String property = context.getEnvironment().getProperty("the.property");
|
||||
assertThat(property).isEqualTo("fromspecificlocation");
|
||||
@@ -662,7 +663,7 @@ public class ConfigFileApplicationListenerTests {
|
||||
public void propertySourceAnnotationInProfile() throws Exception {
|
||||
SpringApplication application = new SpringApplication(
|
||||
WithPropertySourceInProfile.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
ConfigurableApplicationContext context = application
|
||||
.run("--spring.profiles.active=myprofile");
|
||||
String property = context.getEnvironment().getProperty("the.property");
|
||||
@@ -678,7 +679,7 @@ public class ConfigFileApplicationListenerTests {
|
||||
public void propertySourceAnnotationAndNonActiveProfile() throws Exception {
|
||||
SpringApplication application = new SpringApplication(
|
||||
WithPropertySourceAndProfile.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
ConfigurableApplicationContext context = application.run();
|
||||
String property = context.getEnvironment().getProperty("my.property");
|
||||
assertThat(property).isEqualTo("fromapplicationproperties");
|
||||
@@ -691,7 +692,7 @@ public class ConfigFileApplicationListenerTests {
|
||||
public void propertySourceAnnotationMultipleLocations() throws Exception {
|
||||
SpringApplication application = new SpringApplication(
|
||||
WithPropertySourceMultipleLocations.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
ConfigurableApplicationContext context = application.run();
|
||||
String property = context.getEnvironment().getProperty("the.property");
|
||||
assertThat(property).isEqualTo("frommorepropertiesfile");
|
||||
@@ -704,7 +705,7 @@ public class ConfigFileApplicationListenerTests {
|
||||
public void propertySourceAnnotationMultipleLocationsAndName() throws Exception {
|
||||
SpringApplication application = new SpringApplication(
|
||||
WithPropertySourceMultipleLocationsAndName.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
ConfigurableApplicationContext context = application.run();
|
||||
String property = context.getEnvironment().getProperty("the.property");
|
||||
assertThat(property).isEqualTo("frommorepropertiesfile");
|
||||
@@ -715,7 +716,7 @@ public class ConfigFileApplicationListenerTests {
|
||||
@Test
|
||||
public void activateProfileFromProfileSpecificProperties() throws Exception {
|
||||
SpringApplication application = new SpringApplication(Config.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run("--spring.profiles.active=includeprofile");
|
||||
ConfigurableEnvironment environment = this.context.getEnvironment();
|
||||
assertThat(environment).has(matchingProfile("includeprofile"));
|
||||
@@ -729,7 +730,7 @@ public class ConfigFileApplicationListenerTests {
|
||||
public void profileSubDocumentInSameProfileSpecificFile() throws Exception {
|
||||
// gh-340
|
||||
SpringApplication application = new SpringApplication(Config.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application
|
||||
.run("--spring.profiles.active=activeprofilewithsubdoc");
|
||||
String property = this.context.getEnvironment().getProperty("foobar");
|
||||
@@ -740,7 +741,7 @@ public class ConfigFileApplicationListenerTests {
|
||||
public void profileSubDocumentInDifferentProfileSpecificFile() throws Exception {
|
||||
// gh-4132
|
||||
SpringApplication application = new SpringApplication(Config.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run(
|
||||
"--spring.profiles.active=activeprofilewithdifferentsubdoc,activeprofilewithdifferentsubdoc2");
|
||||
String property = this.context.getEnvironment().getProperty("foobar");
|
||||
@@ -762,7 +763,7 @@ public class ConfigFileApplicationListenerTests {
|
||||
@Test
|
||||
public void customDefaultProfile() throws Exception {
|
||||
SpringApplication application = new SpringApplication(Config.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run("--spring.profiles.default=customdefault");
|
||||
String property = this.context.getEnvironment().getProperty("customdefault");
|
||||
assertThat(property).isEqualTo("true");
|
||||
@@ -771,7 +772,7 @@ public class ConfigFileApplicationListenerTests {
|
||||
@Test
|
||||
public void customDefaultProfileAndActive() throws Exception {
|
||||
SpringApplication application = new SpringApplication(Config.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run("--spring.profiles.default=customdefault",
|
||||
"--spring.profiles.active=dev");
|
||||
String property = this.context.getEnvironment().getProperty("my.property");
|
||||
@@ -784,7 +785,7 @@ public class ConfigFileApplicationListenerTests {
|
||||
public void customDefaultProfileAndActiveFromFile() throws Exception {
|
||||
// gh-5998
|
||||
SpringApplication application = new SpringApplication(Config.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run("--spring.config.name=customprofile",
|
||||
"--spring.profiles.default=customdefault");
|
||||
ConfigurableEnvironment environment = this.context.getEnvironment();
|
||||
@@ -797,7 +798,7 @@ public class ConfigFileApplicationListenerTests {
|
||||
@Test
|
||||
public void additionalProfilesCanBeIncludedFromAnyPropertySource() throws Exception {
|
||||
SpringApplication application = new SpringApplication(Config.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run("--spring.profiles.active=myprofile",
|
||||
"--spring.profiles.include=dev");
|
||||
String property = this.context.getEnvironment().getProperty("my.property");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* 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.
|
||||
@@ -21,6 +21,7 @@ import javax.annotation.PostConstruct;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.context.embedded.PortInUseException;
|
||||
import org.springframework.boot.testutil.InternalOutputCapture;
|
||||
@@ -42,7 +43,8 @@ public class FailureAnalyzersIntegrationTests {
|
||||
@Test
|
||||
public void analysisIsPerformed() {
|
||||
try {
|
||||
new SpringApplicationBuilder(TestConfiguration.class).web(false).run();
|
||||
new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE)
|
||||
.run();
|
||||
fail("Application started successfully");
|
||||
}
|
||||
catch (Exception ex) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* 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.
|
||||
@@ -23,6 +23,7 @@ import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
@@ -48,7 +49,7 @@ public class LiquibaseServiceLocatorApplicationListenerTests {
|
||||
@Test
|
||||
public void replacesServiceLocator() throws Exception {
|
||||
SpringApplication application = new SpringApplication(Conf.class);
|
||||
application.setWebEnvironment(false);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run();
|
||||
ServiceLocator instance = ServiceLocator.getInstance();
|
||||
Field field = ReflectionUtils.findField(ServiceLocator.class, "classResolver");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* 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.
|
||||
@@ -21,6 +21,7 @@ import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.context.event.ApplicationStartingEvent;
|
||||
import org.springframework.boot.testutil.InternalOutputCapture;
|
||||
@@ -43,7 +44,7 @@ public class LoggingApplicationListenerIntegrationTests {
|
||||
@Test
|
||||
public void loggingSystemRegisteredInTheContext() {
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder(
|
||||
SampleService.class).web(false).run();
|
||||
SampleService.class).web(WebApplicationType.NONE).run();
|
||||
try {
|
||||
SampleService service = context.getBean(SampleService.class);
|
||||
assertThat(service.loggingSystem).isNotNull();
|
||||
@@ -55,8 +56,8 @@ public class LoggingApplicationListenerIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void loggingPerformedDuringChildApplicationStartIsNotLost() {
|
||||
new SpringApplicationBuilder(Config.class).web(false).child(Config.class)
|
||||
.web(false)
|
||||
new SpringApplicationBuilder(Config.class).web(WebApplicationType.NONE)
|
||||
.child(Config.class).web(WebApplicationType.NONE)
|
||||
.listeners(new ApplicationListener<ApplicationStartingEvent>() {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
Reference in New Issue
Block a user