spring-bootspring-cloud-config-serverspring-boot-configuration

spring boot config server production setup for error "You need to configure a uri for the git repository."


I have a Spring Boot Config server that reads some properties from the local resources folder. The foldersetup is this:

In resources/application.properties, I have the following:

spring.application.name=configserver
server.port=8012
spring.profiles.active=native
spring.cloud.config.server.native.search-locations=classpath:/config

This works just fine in dev. But in Production, in the Kubernetes manifest, I pass the following:

env:
  - name: SPRING_PROFILES_ACTIVE
    value: "production"

And I'm getting the following error from the pod that attempts to start this:

2023-02-27 22:56:43.192 INFO 1 --- [ main] .c.c.ConfigServerApplication : The following 1 profile is active: "production" 2023-02-27 22:56:48.082 INFO 1 --- [
main] o.s.cloud.context.scope.GenericScope : BeanFactory id=f34714c7-eae5-36bb-b71e-023da97acc11 2023-02-27 22:56:50.190 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http) 2023-02-27 22:56:50.205 INFO 1 --- [ main] o.apache.catalina.core.StandardService
: Starting service [Tomcat] 2023-02-27 22:56:50.205 INFO 1 --- [
main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.58] 2023-02-27 22:56:50.781 INFO 1 --- [
main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2023-02-27 22:56:50.781 INFO 1 --- [
main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 7294 ms 2023-02-27 22:56:57.701 WARN 1 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultEnvironmentRepository' defined in class path resource [org/springframework/cloud/config/server/config/DefaultRepositoryConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: You need to configure a uri for the git repository. 2023-02-27 22:56:57.704 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat] 2023-02-27 22:56:57.796 INFO 1 --- [ main] ConditionEvaluationReportLoggingListener :

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2023-02-27 22:56:57.993 ERROR 1 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter
:

*************************** APPLICATION FAILED TO START


Description:

Invalid config server configuration.

Action:

If you are using the git profile, you need to set a Git URI in your configuration. If you have set spring.cloud.config.server.bootstrap=true, you need to use a composite configuration.

I don't understand enough about profiles in Spring Boot, but how do I run the config server in Production and specify native for the paths?


Solution

  • The problem is that SPRING_PROFILES_ACTIVE environment variable overrides spring.profiles.active specified in application.properties and thus makes native not active.

    You should replace spring.profiles.active with spring.profiles.include.

    Sometimes, it is useful to have properties that add to the active profiles rather than replace them. The spring.profiles.include property can be used to add active profiles on top of those activated by the spring.profiles.active property.

    Similar to spring.profiles.active, spring.profiles.include can only be used in non-profile specific documents.

    For reference: Spring Docs - Adding Active Profiles