diff --git a/docs/src/main/asciidoc/spring-cloud-config.adoc b/docs/src/main/asciidoc/spring-cloud-config.adoc index ea7fd3ff..12897be0 100644 --- a/docs/src/main/asciidoc/spring-cloud-config.adoc +++ b/docs/src/main/asciidoc/spring-cloud-config.adoc @@ -240,7 +240,7 @@ spring: NOTE: Spring Cloud guesses that a pattern containing a profile that does not end in `\*` implies that you actually want to match a list of profiles starting with this pattern (so `*/staging` is a shortcut for `["\*/staging", "*/staging,*"]`, and so on). This is common where, for instance, you need to run applications in the "`development`" profile locally but also the "`cloud`" profile remotely. -Every repository can also optionally store config files in sub-directories, and patterns to search for those directories can be specified as `searchPaths`. +Every repository can also optionally store config files in sub-directories, and patterns to search for those directories can be specified as `search-paths`. The following example shows a config file at the top level: [source,yaml] @@ -251,7 +251,9 @@ spring: server: git: uri: https://github.com/spring-cloud-samples/config-repo - searchPaths: foo,bar* + search-paths: + - foo + - bar* ---- In the preceding example, the server searches for config files in the top level and in the `foo/` sub-directory and also any sub-directory whose name begins with `bar`. @@ -451,7 +453,7 @@ spring: server: git: uri: https://github.com/spring-cloud-samples/config-repo - searchPaths: '{application}' + search-paths: '{application}' ---- The preceding listing causes a search of the repository for files in the same name as the directory (as well as the top level). diff --git a/spring-cloud-config-sample/src/test/java/sample/ApplicationBootstrapTests.java b/spring-cloud-config-sample/src/test/java/sample/ApplicationBootstrapTests.java index 27acb21a..885d1150 100644 --- a/spring-cloud-config-sample/src/test/java/sample/ApplicationBootstrapTests.java +++ b/spring-cloud-config-sample/src/test/java/sample/ApplicationBootstrapTests.java @@ -29,6 +29,7 @@ import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointPr import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentProperties; import org.springframework.cloud.config.server.test.ConfigServerTestUtils; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.test.context.junit4.SpringRunner; @@ -104,4 +105,12 @@ public class ApplicationBootstrapTests { assertThat(property).containsEntry("value", "bar"); } + @Test + public void propertiesBeansRegisterByCompositeEnvBeanFactoryPostProcessor() { + String[] beanNames = server + .getBeanNamesForType(MultipleJGitEnvironmentProperties.class); + assertThat(beanNames).isNotNull() + .anyMatch(s -> s.matches("git-env-repo-properties\\d")); + } + } diff --git a/spring-cloud-config-server/pom.xml b/spring-cloud-config-server/pom.xml index 6af747db..864a8e61 100644 --- a/spring-cloud-config-server/pom.xml +++ b/spring-cloud-config-server/pom.xml @@ -13,7 +13,7 @@ org.springframework.cloud spring-cloud-config - 3.0.4-SNAPSHOT + 2.2.7.BUILD-SNAPSHOT .. @@ -40,6 +40,7 @@ org.springframework.boot spring-boot-starter-actuator + true org.springframework.boot diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/composite/CompositeEnvironmentBeanFactoryPostProcessor.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/composite/CompositeEnvironmentBeanFactoryPostProcessor.java index 09c90908..514d4b85 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/composite/CompositeEnvironmentBeanFactoryPostProcessor.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/composite/CompositeEnvironmentBeanFactoryPostProcessor.java @@ -45,8 +45,11 @@ public class CompositeEnvironmentBeanFactoryPostProcessor implements BeanFactory this.environment = environment; } + @SuppressWarnings("unchecked") @Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { + BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory; + List typePropertyList = CompositeUtils.getCompositeTypeList(this.environment); for (int i = 0; i < typePropertyList.size(); i++) { String type = typePropertyList.get(i); @@ -56,12 +59,18 @@ public class CompositeEnvironmentBeanFactoryPostProcessor implements BeanFactory Class propertiesClass; propertiesClass = (Class) factoryTypes[1]; EnvironmentRepositoryProperties properties = bindProperties(i, propertiesClass, this.environment); + AbstractBeanDefinition propertiesDefinition = BeanDefinitionBuilder + .genericBeanDefinition(EnvironmentRepositoryProperties.class, + () -> properties) + .getBeanDefinition(); + String propertiesBeanName = String.format("%s-env-repo-properties%d", type, + i); + registry.registerBeanDefinition(propertiesBeanName, propertiesDefinition); AbstractBeanDefinition beanDefinition = BeanDefinitionBuilder .genericBeanDefinition(EnvironmentRepository.class).setFactoryMethodOnBean("build", factoryName) .addConstructorArgValue(properties).getBeanDefinition(); String beanName = String.format("%s-env-repo%d", type, i); - BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory; registry.registerBeanDefinition(beanName, beanDefinition); } } diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/config/EnvironmentRepositoryConfiguration.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/config/EnvironmentRepositoryConfiguration.java index 2fee423e..50f75bea 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/config/EnvironmentRepositoryConfiguration.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/config/EnvironmentRepositoryConfiguration.java @@ -27,6 +27,7 @@ import org.eclipse.jgit.api.TransportConfigCallback; import org.tmatesoft.svn.core.SVNException; import org.springframework.beans.factory.ObjectProvider; +import org.springframework.boot.actuate.health.AbstractHealthIndicator; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -107,12 +108,6 @@ import org.springframework.vault.core.VaultTemplate; AwsS3RepositoryConfiguration.class, DefaultRepositoryConfiguration.class }) public class EnvironmentRepositoryConfiguration { - @Bean - @ConditionalOnProperty(value = "spring.cloud.config.server.health.enabled", matchIfMissing = true) - public ConfigServerHealthIndicator configServerHealthIndicator(EnvironmentRepository repository) { - return new ConfigServerHealthIndicator(repository); - } - @Bean @ConditionalOnMissingBean(search = SearchStrategy.CURRENT) public MultipleJGitEnvironmentProperties multipleJGitEnvironmentProperties() { @@ -125,6 +120,20 @@ public class EnvironmentRepositoryConfiguration { return new HttpRequestConfigTokenProvider(httpRequest); } + @Configuration(proxyBeanMethods = false) + @ConditionalOnClass(AbstractHealthIndicator.class) + @ConditionalOnProperty(value = "spring.cloud.config.server.health.enabled", + matchIfMissing = true) + protected static class ConfigServerActuatorConfiguration { + + @Bean + public ConfigServerHealthIndicator configServerHealthIndicator( + EnvironmentRepository repository) { + return new ConfigServerHealthIndicator(repository); + } + + } + @Configuration(proxyBeanMethods = false) @ConditionalOnProperty("spring.cloud.config.server.consul.watch.enabled") protected static class ConsulEnvironmentWatchConfiguration { diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/vault/authentication/PcfClientAuthenticationProvider.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/vault/authentication/PcfClientAuthenticationProvider.java index ef4bc33f..38a9e471 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/vault/authentication/PcfClientAuthenticationProvider.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/vault/authentication/PcfClientAuthenticationProvider.java @@ -52,6 +52,10 @@ public class PcfClientAuthenticationProvider extends SpringVaultClientAuthentica else { builder.instanceCertificate(new ResourceCredentialSupplier(resolveEnvVariable("CF_INSTANCE_CERT"))); } + else { + builder.instanceCertificate(new ResourceCredentialSupplier( + resolveEnvVariable("CF_INSTANCE_CERT"))); + } if (pcfProperties.getInstanceKey() != null) { builder.instanceKey(new ResourceCredentialSupplier(pcfProperties.getInstanceKey())); @@ -59,6 +63,10 @@ public class PcfClientAuthenticationProvider extends SpringVaultClientAuthentica else { builder.instanceKey(new ResourceCredentialSupplier(resolveEnvVariable("CF_INSTANCE_KEY"))); } + else { + builder.instanceKey(new ResourceCredentialSupplier( + resolveEnvVariable("CF_INSTANCE_KEY"))); + } return new PcfAuthentication(builder.build(), vaultRestOperations); } diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CompositeClasspathTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CompositeClasspathTests.java index 1bb2d54a..dec75a79 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CompositeClasspathTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CompositeClasspathTests.java @@ -24,6 +24,8 @@ import org.springframework.cloud.config.server.composite.CompositeUtils; import org.springframework.cloud.test.ClassPathExclusions; import org.springframework.cloud.test.ModifiedClassPathRunner; +import static org.assertj.core.api.Assertions.assertThat; + public class CompositeClasspathTests { @RunWith(ModifiedClassPathRunner.class) @@ -46,6 +48,29 @@ public class CompositeClasspathTests { } + @RunWith(ModifiedClassPathRunner.class) + @ClassPathExclusions({ "spring-jdbc-*.jar", "spring-data-redis-*.jar", + "spring-boot-actuator-*.jar" }) + public static class NoActuatorTests { + + @Test + public void contextLoads() { + new WebApplicationContextRunner() + .withUserConfiguration(ConfigServerApplication.class) + .withPropertyValues("spring.profiles.active:test,composite", + "spring.jmx.enabled=false", + "spring.config.name:compositeconfigserver", + "spring.cloud.config.server.composite[0].uri:file:./target/repos/config-repo", + "spring.cloud.config.server.composite[0].type:git") + .run(context -> { + CompositeUtils.getCompositeTypeList(context.getEnvironment()); + assertThat(context) + .doesNotHaveBean("configServerHealthIndicator"); + }); + } + + } + @RunWith(ModifiedClassPathRunner.class) @ClassPathExclusions("httpclient-*.jar") public static class HttpClientTests {