Use 'application' if spring.application.name is not set.

Also log a warning.

fixes gh-152
This commit is contained in:
Spencer Gibb
2017-11-01 13:36:26 -04:00
parent 428650b915
commit b3b9477cac
2 changed files with 47 additions and 0 deletions

View File

@@ -81,6 +81,11 @@ public class ZookeeperPropertySourceLocator implements PropertySourceLocator {
if (environment instanceof ConfigurableEnvironment) {
ConfigurableEnvironment env = (ConfigurableEnvironment) environment;
String appName = env.getProperty("spring.application.name");
if (appName == null) {
// use default "application" (which config client does)
appName = "application";
log.warn("spring.application.name is not set. Using default of 'application'");
}
List<String> profiles = Arrays.asList(env.getActiveProfiles());
String root = this.properties.getRoot();

View File

@@ -0,0 +1,42 @@
/*
* Copyright 2013-2015 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.zookeeper.config;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.api.GetChildrenBuilder;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.mock.env.MockEnvironment;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/**
* @author Spencer Gibb
*/
public class ZookeeperPropertySourceLocatorNoApplicationNameTests {
@Test
public void defaultSpringApplicationNameWorks() {
CuratorFramework curator = mock(CuratorFramework.class);
when(curator.getChildren()).thenReturn(mock(GetChildrenBuilder.class));
ZookeeperPropertySourceLocator locator = new ZookeeperPropertySourceLocator(curator, new ZookeeperConfigProperties());
locator.locate(new MockEnvironment());
}
}