Make webflux optional
This commit is contained in:
6
pom.xml
6
pom.xml
@@ -91,6 +91,12 @@
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-test-support</artifactId>
|
||||
<scope>test</scope>
|
||||
<version>${spring-cloud-commons.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
|
||||
|
||||
@@ -76,6 +76,11 @@
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-test-support</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.projectreactor</groupId>
|
||||
<artifactId>reactor-test</artifactId>
|
||||
|
||||
@@ -104,7 +104,8 @@ import rx.RxReactiveStreams;
|
||||
@ConditionalOnProperty(name = "spring.cloud.gateway.enabled", matchIfMissing = true)
|
||||
@EnableConfigurationProperties
|
||||
@AutoConfigureBefore(HttpHandlerAutoConfiguration.class)
|
||||
@AutoConfigureAfter(GatewayLoadBalancerClientAutoConfiguration.class)
|
||||
@AutoConfigureAfter({GatewayLoadBalancerClientAutoConfiguration.class, GatewayClassPathWarningAutoConfiguration.class})
|
||||
@ConditionalOnClass(DispatcherHandler.class)
|
||||
public class GatewayAutoConfiguration {
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -2,18 +2,37 @@ package org.springframework.cloud.gateway.config;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnClass(name = "org.springframework.web.servlet.DispatcherServlet")
|
||||
@AutoConfigureBefore(GatewayAutoConfiguration.class)
|
||||
public class GatewayClassPathWarningAutoConfiguration {
|
||||
|
||||
private static final Log log = LogFactory.getLog(GatewayClassPathWarningAutoConfiguration.class);
|
||||
private static final String BORDER = "\n\n**********************************************************\n\n";
|
||||
|
||||
public GatewayClassPathWarningAutoConfiguration() {
|
||||
log.warn(BORDER+"Spring MVC found on classpath, which is incompatible with Spring Cloud Gateway at this time. "+
|
||||
"Please remove spring-boot-starter-web dependency."+BORDER);
|
||||
@Configuration
|
||||
@ConditionalOnClass(name = "org.springframework.web.servlet.DispatcherServlet")
|
||||
protected static class SpringMvcFoundOnClasspathConfiguration {
|
||||
|
||||
public SpringMvcFoundOnClasspathConfiguration() {
|
||||
log.warn(BORDER+"Spring MVC found on classpath, which is incompatible with Spring Cloud Gateway at this time. "+
|
||||
"Please remove spring-boot-starter-web dependency."+BORDER);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnMissingClass("org.springframework.web.reactive.DispatcherHandler")
|
||||
protected static class WebfluxMissingFromClasspathConfiguration {
|
||||
|
||||
public WebfluxMissingFromClasspathConfiguration() {
|
||||
log.warn(BORDER+"Spring Webflux is missing from the classpath, which is required for Spring Cloud Gateway at this time. "+
|
||||
"Please add spring-boot-starter-webflux dependency."+BORDER);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,12 +25,13 @@ import org.springframework.cloud.gateway.filter.LoadBalancerClientFilter;
|
||||
import org.springframework.cloud.netflix.ribbon.RibbonAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.reactive.DispatcherHandler;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass({LoadBalancerClient.class, RibbonAutoConfiguration.class})
|
||||
@ConditionalOnClass({LoadBalancerClient.class, RibbonAutoConfiguration.class, DispatcherHandler.class})
|
||||
@AutoConfigureAfter(RibbonAutoConfiguration.class)
|
||||
public class GatewayLoadBalancerClientAutoConfiguration {
|
||||
|
||||
|
||||
@@ -22,12 +22,13 @@ import org.springframework.data.redis.serializer.RedisSerializationContext;
|
||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
import org.springframework.scripting.support.ResourceScriptSource;
|
||||
import org.springframework.web.reactive.DispatcherHandler;
|
||||
|
||||
@Configuration
|
||||
@AutoConfigureAfter(RedisReactiveAutoConfiguration.class)
|
||||
@AutoConfigureBefore(GatewayAutoConfiguration.class)
|
||||
@ConditionalOnBean(ReactiveRedisTemplate.class)
|
||||
@ConditionalOnClass(RedisTemplate.class)
|
||||
@ConditionalOnClass({RedisTemplate.class, DispatcherHandler.class})
|
||||
class GatewayRedisAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Auto Configure
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
org.springframework.cloud.gateway.config.GatewayAutoConfiguration,\
|
||||
org.springframework.cloud.gateway.config.GatewayClassPathWarningAutoConfiguration,\
|
||||
org.springframework.cloud.gateway.config.GatewayAutoConfiguration,\
|
||||
org.springframework.cloud.gateway.config.GatewayLoadBalancerClientAutoConfiguration,\
|
||||
org.springframework.cloud.gateway.config.GatewayRedisAutoConfiguration
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2013-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.cloud.gateway.test;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.cloud.test.ClassPathExclusions;
|
||||
import org.springframework.cloud.test.ModifiedClassPathRunner;
|
||||
|
||||
@RunWith(ModifiedClassPathRunner.class)
|
||||
@ClassPathExclusions({"spring-webflux-*.jar"})
|
||||
public class WebfluxNotIncludedTests {
|
||||
|
||||
@Test
|
||||
public void noWebfluxWorks() {
|
||||
new SpringApplication(Config.class).run();
|
||||
}
|
||||
|
||||
@SpringBootConfiguration
|
||||
@EnableAutoConfiguration
|
||||
public static class Config {}
|
||||
}
|
||||
@@ -24,9 +24,5 @@
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-gateway-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-webflux</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
Reference in New Issue
Block a user