Use 'application' if spring.application.name is not set.
Also log a warning. fixes gh-152
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user