Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions docs/modules/ROOT/pages/server/embedding.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,26 @@ The choice between embedding the Config Server and running it as a standalone se
When embedding the Config Server in a multi-application environment (for example, if each microservice embeds its own Config Server), each application independently connects to the Git repository. This means each application must possess valid Git credentials and encryption keys, which can complicate secret rotation and auditing.
====

[[disabling-the-default-environment-repository]]
== Disabling the Default Environment Repository

When embedding Config Server in another application, you may want to disable the default environment repository so that the server does not configure a default Git repository when no `EnvironmentRepository` has been explicitly configured.

You can disable the default environment repository by setting the following property:

[source,yaml]
----
spring:
cloud:
config:
server:
default-repository:
enabled: false
----

When this property is set to `false`, the default Git environment repository is not created. This is useful when embedding Config Server in an application that should not use the default Git repository.

By default, this property is `true`, preserving the existing behavior.

This property controls the creation of the default repository. The `spring.cloud.config.server.accept-empty` property separately controls whether the server returns an HTTP 404 response when the requested application is not found.

Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@ public MongoDbEnvironmentRepositoryFactory mongoDbEnvironmentRepositoryFactory(M
class DefaultRepositoryConfiguration {

@Bean
@ConditionalOnProperty(prefix = "spring.cloud.config.server.default-repository", name = "enabled",
havingValue = "true", matchIfMissing = true)
public MultipleJGitEnvironmentRepository defaultEnvironmentRepository(
MultipleJGitEnvironmentRepositoryFactory gitEnvironmentRepositoryFactory,
MultipleJGitEnvironmentProperties environmentProperties) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.springframework.cloud.config.server.environment.EnvironmentConfigTokenProvider;
import org.springframework.cloud.config.server.environment.EnvironmentRepository;
import org.springframework.cloud.config.server.environment.GcsEnvironmentRepositoryFactory;
import org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentRepository;
import org.springframework.cloud.config.server.support.AzureDevOpsWorkloadIdentitySupport;
import org.springframework.cloud.config.server.support.GitCredentialsProviderFactory;
import org.springframework.context.annotation.Bean;
Expand Down Expand Up @@ -191,6 +192,18 @@ public void azureDevOpsWorkloadIdentitySupportBeanExists() {
});
}

@Test
public void defaultEnvironmentRepositoryCanBeDisabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EnvironmentRepositoryConfiguration.class, TestBeans.class))
.withBean(EnvironmentRepository.class, () -> mock(EnvironmentRepository.class))
.withPropertyValues("spring.cloud.config.server.default-repository.enabled=false")
.run((context) -> {
assertThat(context).hasNotFailed();
assertThat(context).doesNotHaveBean(MultipleJGitEnvironmentRepository.class);
});
}

@TestConfiguration
public static class TestBeans {

Expand Down
Loading