diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/EnableGateway.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/EnableGateway.java new file mode 100644 index 000000000..e51830c8b --- /dev/null +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/EnableGateway.java @@ -0,0 +1,44 @@ +/* + * 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; + +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.gateway.config.GatewayConfiguration; +import org.springframework.context.annotation.Import; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotation to activate Spring Cloud Gateway configuration {@link org.springframework.cloud.gateway.config.GatewayAutoConfiguration} + * + * @author Spencer Gibb + * + */ + +@EnableDiscoveryClient +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Import(GatewayConfiguration.class) +public @interface EnableGateway { + +} diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java index 14f27eac6..99f250f6f 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java @@ -77,6 +77,7 @@ import rx.RxReactiveStreams; * @author Spencer Gibb */ @Configuration +@ConditionalOnBean(GatewayConfiguration.Marker.class) @EnableConfigurationProperties public class GatewayAutoConfiguration { diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/config/GatewayConfiguration.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/config/GatewayConfiguration.java new file mode 100644 index 000000000..55690d2ad --- /dev/null +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/config/GatewayConfiguration.java @@ -0,0 +1,34 @@ +/* + * 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.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @author Spencer Gibb + */ +@Configuration +public class GatewayConfiguration { + @Bean + public Marker gatewayMarker() { + return new Marker(); + } + + class Marker { } +} diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/AddRequestHeaderRouteFilterIntegrationTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/AddRequestHeaderRouteFilterIntegrationTests.java index 55c3178b6..35da9566c 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/AddRequestHeaderRouteFilterIntegrationTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/AddRequestHeaderRouteFilterIntegrationTests.java @@ -24,6 +24,7 @@ import org.junit.runner.RunWith; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.cloud.gateway.EnableGateway; import org.springframework.cloud.gateway.test.BaseWebClientTests; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; @@ -61,6 +62,7 @@ public class AddRequestHeaderRouteFilterIntegrationTests extends BaseWebClientTe @EnableAutoConfiguration @SpringBootConfiguration + @EnableGateway public static class TestConfig { } } diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/AddRequestParameterRouteFilterIntegrationTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/AddRequestParameterRouteFilterIntegrationTests.java index aa3011783..61c0ba8f3 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/AddRequestParameterRouteFilterIntegrationTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/AddRequestParameterRouteFilterIntegrationTests.java @@ -24,6 +24,7 @@ import org.junit.runner.RunWith; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.cloud.gateway.EnableGateway; import org.springframework.cloud.gateway.test.BaseWebClientTests; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; @@ -70,6 +71,7 @@ public class AddRequestParameterRouteFilterIntegrationTests extends BaseWebClien @EnableAutoConfiguration @SpringBootConfiguration + @EnableGateway public static class TestConfig { } } diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/RedirectToRouteFilterIntegrationTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/RedirectToRouteFilterIntegrationTests.java index f9f56c577..5a0606c1e 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/RedirectToRouteFilterIntegrationTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/RedirectToRouteFilterIntegrationTests.java @@ -22,6 +22,7 @@ import org.junit.runner.RunWith; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.cloud.gateway.EnableGateway; import org.springframework.cloud.gateway.test.BaseWebClientTests; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; @@ -62,6 +63,7 @@ public class RedirectToRouteFilterIntegrationTests extends BaseWebClientTests { @EnableAutoConfiguration @SpringBootConfiguration + @EnableGateway public static class TestConfig { } } diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/RemoveNonProxyHeadersRouteFilterIntegrationTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/RemoveNonProxyHeadersRouteFilterIntegrationTests.java index 3e23f69e9..d7b816c54 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/RemoveNonProxyHeadersRouteFilterIntegrationTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/RemoveNonProxyHeadersRouteFilterIntegrationTests.java @@ -24,6 +24,7 @@ import org.junit.runner.RunWith; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.cloud.gateway.EnableGateway; import org.springframework.cloud.gateway.test.BaseWebClientTests; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; @@ -68,6 +69,7 @@ public class RemoveNonProxyHeadersRouteFilterIntegrationTests extends BaseWebCli @EnableAutoConfiguration @SpringBootConfiguration + @EnableGateway public static class TestConfig { } } diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/RemoveRequestHeaderRouteFilterIntegrationTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/RemoveRequestHeaderRouteFilterIntegrationTests.java index 35299f5c2..63eb0fbdd 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/RemoveRequestHeaderRouteFilterIntegrationTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/RemoveRequestHeaderRouteFilterIntegrationTests.java @@ -24,6 +24,7 @@ import org.junit.runner.RunWith; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.cloud.gateway.EnableGateway; import org.springframework.cloud.gateway.test.BaseWebClientTests; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; @@ -62,6 +63,7 @@ public class RemoveRequestHeaderRouteFilterIntegrationTests extends BaseWebClien @EnableAutoConfiguration @SpringBootConfiguration + @EnableGateway public static class TestConfig { } } diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/RewritePathRouteFilterIntegrationTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/RewritePathRouteFilterIntegrationTests.java index 1c1b00d28..5d90e075d 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/RewritePathRouteFilterIntegrationTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/RewritePathRouteFilterIntegrationTests.java @@ -22,14 +22,13 @@ import org.junit.runner.RunWith; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.cloud.gateway.EnableGateway; import org.springframework.cloud.gateway.test.BaseWebClientTests; -import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.reactive.function.client.ClientResponse; -import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; import static org.springframework.cloud.gateway.test.TestUtils.assertStatus; @@ -59,6 +58,7 @@ public class RewritePathRouteFilterIntegrationTests extends BaseWebClientTests { @EnableAutoConfiguration @SpringBootConfiguration + @EnableGateway public static class TestConfig { } } diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/SecureHeadersRouteFilterIntegrationTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/SecureHeadersRouteFilterIntegrationTests.java index cc70e8f42..3ef89410d 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/SecureHeadersRouteFilterIntegrationTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/SecureHeadersRouteFilterIntegrationTests.java @@ -22,6 +22,7 @@ import org.junit.runner.RunWith; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.cloud.gateway.EnableGateway; import org.springframework.cloud.gateway.test.BaseWebClientTests; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; @@ -78,6 +79,7 @@ public class SecureHeadersRouteFilterIntegrationTests extends BaseWebClientTests @EnableAutoConfiguration @SpringBootConfiguration + @EnableGateway public static class TestConfig { } } diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/SetPathRouteFilterIntegrationTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/SetPathRouteFilterIntegrationTests.java index 76859e8e5..4aa99e4b8 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/SetPathRouteFilterIntegrationTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/SetPathRouteFilterIntegrationTests.java @@ -22,6 +22,7 @@ import org.junit.runner.RunWith; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.cloud.gateway.EnableGateway; import org.springframework.cloud.gateway.test.BaseWebClientTests; import org.springframework.http.HttpStatus; import org.springframework.test.annotation.DirtiesContext; @@ -57,6 +58,7 @@ public class SetPathRouteFilterIntegrationTests extends BaseWebClientTests { @EnableAutoConfiguration @SpringBootConfiguration + @EnableGateway public static class TestConfig { } } diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/SetResponseRouteFilterIntegrationTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/SetResponseRouteFilterIntegrationTests.java index 5df11db09..efee50265 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/SetResponseRouteFilterIntegrationTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/SetResponseRouteFilterIntegrationTests.java @@ -22,6 +22,7 @@ import org.junit.runner.RunWith; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.cloud.gateway.EnableGateway; import org.springframework.cloud.gateway.test.BaseWebClientTests; import org.springframework.http.HttpHeaders; import org.springframework.test.annotation.DirtiesContext; @@ -59,6 +60,7 @@ public class SetResponseRouteFilterIntegrationTests extends BaseWebClientTests { @EnableAutoConfiguration @SpringBootConfiguration + @EnableGateway public static class TestConfig { } } diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/SetStatusRouteFilterIntegrationTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/SetStatusRouteFilterIntegrationTests.java index c4a0c4423..39b430274 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/SetStatusRouteFilterIntegrationTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/route/SetStatusRouteFilterIntegrationTests.java @@ -22,6 +22,7 @@ import org.junit.runner.RunWith; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.cloud.gateway.EnableGateway; import org.springframework.cloud.gateway.test.BaseWebClientTests; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; @@ -68,6 +69,7 @@ public class SetStatusRouteFilterIntegrationTests extends BaseWebClientTests { @EnableAutoConfiguration @SpringBootConfiguration + @EnableGateway public static class TestConfig { } } diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/BaseWebClientTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/BaseWebClientTests.java index b921bfdfd..2210c80b6 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/BaseWebClientTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/BaseWebClientTests.java @@ -23,6 +23,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.Before; import org.springframework.boot.context.embedded.LocalServerPort; +import org.springframework.cloud.gateway.EnableGateway; import org.springframework.cloud.gateway.api.Route; import org.springframework.cloud.gateway.filter.GlobalFilter; import org.springframework.context.annotation.Bean; @@ -61,6 +62,7 @@ public class BaseWebClientTests { } @Configuration + @EnableGateway protected static class DefaultTestConfig { private static final Log log = LogFactory.getLog(DefaultTestConfig.class); diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/FormIntegrationTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/FormIntegrationTests.java index f2549c77c..e0b9937c6 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/FormIntegrationTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/FormIntegrationTests.java @@ -25,6 +25,7 @@ import org.junit.runner.RunWith; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.cloud.gateway.EnableGateway; import org.springframework.core.io.ClassPathResource; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; @@ -98,6 +99,7 @@ public class FormIntegrationTests extends BaseWebClientTests { @EnableAutoConfiguration @SpringBootConfiguration + @EnableGateway //@Import(DefaultTestConfig.class) public static class TestConfig { } diff --git a/spring-cloud-gateway-sample/src/main/java/org/springframework/cloud/gateway/sample/GatewaySampleApplication.java b/spring-cloud-gateway-sample/src/main/java/org/springframework/cloud/gateway/sample/GatewaySampleApplication.java index 24a84701b..1fc1b3f85 100644 --- a/spring-cloud-gateway-sample/src/main/java/org/springframework/cloud/gateway/sample/GatewaySampleApplication.java +++ b/spring-cloud-gateway-sample/src/main/java/org/springframework/cloud/gateway/sample/GatewaySampleApplication.java @@ -20,6 +20,7 @@ package org.springframework.cloud.gateway.sample; import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.cloud.gateway.EnableGateway; import org.springframework.cloud.gateway.api.RouteLocator; import org.springframework.cloud.gateway.config.GatewayProperties; import org.springframework.cloud.gateway.config.PropertiesRouteLocator; @@ -35,6 +36,7 @@ import reactor.core.publisher.Flux; */ @SpringBootConfiguration @EnableAutoConfiguration +@EnableGateway public class GatewaySampleApplication { @Bean public PropertiesRouteLocator propertiesRouteLocator(GatewayProperties properties) {