Fix IllegalState issue when using the core module outside of kubernetes.

This commit is contained in:
Ioannis Canellos
2016-04-23 11:35:17 +03:00
parent b466ff2f91
commit a28447d5f8

View File

@@ -28,6 +28,7 @@ import org.springframework.core.env.PropertySource;
public class ConfigMapPropertySourceLocator implements PropertySourceLocator {
private static final String SPRING_APPLICATION_NAME = "spring.application.name";
private static final String FALLBACK_APPLICATION_NAME = "application";
private final KubernetesClient client;
private final ConfigMapConfigProperties properties;
@@ -41,7 +42,7 @@ public class ConfigMapPropertySourceLocator implements PropertySourceLocator {
public PropertySource<?> locate(Environment environment) {
if (environment instanceof ConfigurableEnvironment) {
ConfigurableEnvironment env = (ConfigurableEnvironment) environment;
String appName = env.getProperty(SPRING_APPLICATION_NAME);
String appName = env.getProperty(SPRING_APPLICATION_NAME, FALLBACK_APPLICATION_NAME);
String name = properties.getName() == null || properties.getName().isEmpty() ? appName : properties.getName();
String namespace = properties.getNamespace();
return new ConfigMapPropertySource(client, name, namespace);