Work around bootstrap starting reactive server
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package org.springframework.cloud.gateway.config;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.MapPropertySource;
|
||||
|
||||
import static org.springframework.cloud.bootstrap.BootstrapApplicationListener.BOOTSTRAP_PROPERTY_SOURCE_NAME;
|
||||
import static org.springframework.cloud.bootstrap.BootstrapApplicationListener.DEFAULT_ORDER;
|
||||
|
||||
/**
|
||||
* Reenables reactive http server after bootstrap.
|
||||
* TODO: remove when boot 2.0 handles the NONE web case
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
public class PostBootstrapApplicationListener
|
||||
implements ApplicationListener<ApplicationEnvironmentPreparedEvent>, Ordered {
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
|
||||
ConfigurableEnvironment environment = event.getEnvironment();
|
||||
// don't listen to events in a bootstrap context
|
||||
if (environment.getPropertySources().contains(BOOTSTRAP_PROPERTY_SOURCE_NAME)) {
|
||||
return;
|
||||
}
|
||||
final Map<String, Object> map = Collections.singletonMap("spring.reactive.enabled", "true");
|
||||
environment.getPropertySources().addBefore("bootstrap-web-disabled",
|
||||
new MapPropertySource("bootstrap-web-reenable", map));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return DEFAULT_ORDER+1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package org.springframework.cloud.gateway.config;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.MapPropertySource;
|
||||
|
||||
import static org.springframework.cloud.bootstrap.BootstrapApplicationListener.BOOTSTRAP_PROPERTY_SOURCE_NAME;
|
||||
import static org.springframework.cloud.bootstrap.BootstrapApplicationListener.DEFAULT_ORDER;
|
||||
|
||||
/**
|
||||
* Disables reactive http server just before bootstrap.
|
||||
* TODO: remove when boot 2.0 handles the NONE web case
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
public class PreBootstrapApplicationListener
|
||||
implements ApplicationListener<ApplicationEnvironmentPreparedEvent>, Ordered {
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
|
||||
ConfigurableEnvironment environment = event.getEnvironment();
|
||||
// don't listen to events in a bootstrap context
|
||||
if (environment.getPropertySources().contains(BOOTSTRAP_PROPERTY_SOURCE_NAME)) {
|
||||
return;
|
||||
}
|
||||
final Map<String, Object> map = Collections.singletonMap("spring.reactive.enabled", "false");
|
||||
environment.getPropertySources().addLast(new MapPropertySource("bootstrap-web-disabled", map));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return DEFAULT_ORDER-1;
|
||||
}
|
||||
}
|
||||
@@ -5,3 +5,8 @@ org.springframework.cloud.gateway.config.GatewayAutoConfiguration
|
||||
# Environment Post Processors
|
||||
org.springframework.boot.env.EnvironmentPostProcessor=\
|
||||
org.springframework.cloud.gateway.config.GatewayEnvironmentPostProcessor
|
||||
|
||||
# Application Listeners
|
||||
org.springframework.context.ApplicationListener=\
|
||||
org.springframework.cloud.gateway.config.PreBootstrapApplicationListener,\
|
||||
org.springframework.cloud.gateway.config.PostBootstrapApplicationListener
|
||||
|
||||
@@ -38,8 +38,7 @@ import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = RANDOM_PORT,
|
||||
properties = "spring.cloud.bootstrap.enabled=false")
|
||||
@SpringBootTest(webEnvironment = RANDOM_PORT)
|
||||
@SuppressWarnings("unchecked")
|
||||
public class GatewayIntegrationTests {
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
public class GatewayTestApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.setProperty("spring.cloud.bootstrap.enabled", "false"); //TODO: fix bootstrap
|
||||
SpringApplication.run(GatewayTestApplication.class, args);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user