Adds new env post processor to add default gateway rsocket port.

This commit is contained in:
Spencer Gibb
2019-04-16 13:18:03 -04:00
parent df1181ce27
commit bd9f293d8b
2 changed files with 46 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
/*
* Copyright 2013-2019 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
*
* https://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.rsocket.autoconfigure;
import java.util.Collections;
import java.util.Map;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;
public class GatewayRSocketEnvironmentPostProcessor implements EnvironmentPostProcessor {
@Override
public void postProcessEnvironment(ConfigurableEnvironment env,
SpringApplication application) {
Boolean enabled = env.getProperty("spring.cloud.gateway.rsocket.enabled",
Boolean.class, true);
if (enabled && !env.containsProperty("spring.rsocket.server.port")) {
Map<String, Object> map = Collections
.singletonMap("spring.rsocket.server.port", 7002);
env.getPropertySources()
.addLast(new MapPropertySource("Default Gateway RSocket Port", map));
}
}
}

View File

@@ -1,3 +1,7 @@
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.cloud.gateway.rsocket.autoconfigure.GatewayRSocketAutoConfiguration
# Environment Post Processors
org.springframework.boot.env.EnvironmentPostProcessor=\
org.springframework.cloud.gateway.rsocket.autoconfigure.GatewayRSocketEnvironmentPostProcessor