Merge branch '2.2.x'
This commit is contained in:
@@ -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).
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-config</artifactId>
|
||||
<version>3.0.4-SNAPSHOT</version>
|
||||
<version>2.2.7.BUILD-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
@@ -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<String> 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<? extends EnvironmentRepositoryProperties> propertiesClass;
|
||||
propertiesClass = (Class<? extends EnvironmentRepositoryProperties>) 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user