From fbed1b89e094da68f1491f70193d70033b15768a Mon Sep 17 00:00:00 2001 From: 98001yash Date: Thu, 29 Oct 2026 22:06:04 +0530 Subject: [PATCH 1/3] Allow disabling the default environment repository Signed-off-by: 98001yash --- .../config/EnvironmentRepositoryConfiguration.java | 2 ++ .../EnvironmentRepositoryConfigurationTests.java | 13 +++++++++++++ 2 files changed, 15 insertions(+) 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 0bd66a9254..5f0a292706 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 @@ -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 { diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/EnvironmentRepositoryConfigurationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/EnvironmentRepositoryConfigurationTests.java index f4991a91c2..f3bce54a2f 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/EnvironmentRepositoryConfigurationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/EnvironmentRepositoryConfigurationTests.java @@ -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; @@ -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 { From 83a43dc7b9ae81191d848ed01faa431e4746d17d Mon Sep 17 00:00:00 2001 From: 98001yash Date: Fri, 30 Oct 2026 21:21:29 +0530 Subject: [PATCH 2/3] Document disabling the default environment repository Signed-off-by: 98001yash --- .../pages/server/environment-repository.adoc | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/docs/modules/ROOT/pages/server/environment-repository.adoc b/docs/modules/ROOT/pages/server/environment-repository.adoc index fb134f261a..9ec84f51ed 100644 --- a/docs/modules/ROOT/pages/server/environment-repository.adoc +++ b/docs/modules/ROOT/pages/server/environment-repository.adoc @@ -48,5 +48,27 @@ The server loads the shared `application` files as well as the files named after You can set `spring.cloud.config.server.accept-empty` to `false` so that Server would return a HTTP 404 status, if the application is not found. By default, this flag is set to `true`. +== 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. + NOTE: You cannot place `spring.main.*` properties in a remote `EnvironmentRepository`. These properties are used as part of the application initialization. From 64ff7d539b36c3a188ff3da7a06836a6aa7ac720 Mon Sep 17 00:00:00 2001 From: 98001yash Date: Fri, 30 Oct 2026 21:58:58 +0530 Subject: [PATCH 3/3] Document disabling default repository for embedded server Signed-off-by: 98001yash --- docs/modules/ROOT/pages/server/embedding.adoc | 23 +++++++++++++++++++ .../pages/server/environment-repository.adoc | 22 ------------------ 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/docs/modules/ROOT/pages/server/embedding.adoc b/docs/modules/ROOT/pages/server/embedding.adoc index 805969f081..a9c4334c0e 100644 --- a/docs/modules/ROOT/pages/server/embedding.adoc +++ b/docs/modules/ROOT/pages/server/embedding.adoc @@ -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. + diff --git a/docs/modules/ROOT/pages/server/environment-repository.adoc b/docs/modules/ROOT/pages/server/environment-repository.adoc index 9ec84f51ed..fb134f261a 100644 --- a/docs/modules/ROOT/pages/server/environment-repository.adoc +++ b/docs/modules/ROOT/pages/server/environment-repository.adoc @@ -48,27 +48,5 @@ The server loads the shared `application` files as well as the files named after You can set `spring.cloud.config.server.accept-empty` to `false` so that Server would return a HTTP 404 status, if the application is not found. By default, this flag is set to `true`. -== 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. - NOTE: You cannot place `spring.main.*` properties in a remote `EnvironmentRepository`. These properties are used as part of the application initialization.