Prefer web application type NONE in functional app

This commit is contained in:
Dave Syer
2018-10-17 13:51:42 +01:00
parent 6c0e1bfc2f
commit baabff9a40
3 changed files with 5 additions and 18 deletions

View File

@@ -24,14 +24,12 @@ import java.util.function.Supplier;
import org.springframework.beans.BeanUtils;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.util.ClassUtils;
/**
* @author Dave Syer
@@ -61,19 +59,9 @@ public class SpringApplication extends org.springframework.boot.SpringApplicatio
public SpringApplication(Class<?>... primarySources) {
super(primarySources);
if (ClassUtils.isPresent("org.springframework.web.reactive.DispatcherHandler",
null)) {
// prefer reactive if it is present
setWebApplicationType(WebApplicationType.REACTIVE);
}
}
@Override
public ConfigurableApplicationContext run(String... args) {
if (getWebApplicationType() == WebApplicationType.REACTIVE) {
setApplicationContextClass(ReactiveWebServerApplicationContext.class);
}
return super.run(args);
// Prefer non-web applications, even if a server is on the classpath
setWebApplicationType(WebApplicationType.NONE);
setApplicationContextClass(GenericApplicationContext.class);
}
@Override

View File

@@ -22,9 +22,8 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<wrapper.version>1.0.11.RELEASE</wrapper.version>
<wrapper.version>1.0.17.RELEASE</wrapper.version>
<aws-lambda-events.version>2.0.2</aws-lambda-events.version>
<reactor.version>3.1.2.RELEASE</reactor.version>
<spring-cloud-function.version>2.0.0.BUILD-SNAPSHOT</spring-cloud-function.version>
<start-class>example.Config</start-class>
</properties>

View File

@@ -18,11 +18,11 @@ package example;
import java.util.function.Function;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.function.context.FunctionRegistration;
import org.springframework.cloud.function.context.FunctionType;
import org.springframework.cloud.function.context.SpringApplication;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.support.GenericApplicationContext;