Why does Spring Boot app fetches config from config-server twice with different name
search cancel

Why does Spring Boot app fetches config from config-server twice with different name

book

Article ID: 374770

calendar_today

Updated On:

Products

VMware Tanzu Spring Runtime

Issue/Introduction

Your Spring Boot app is associated with a config-server, during the app start, it fetches configuration from config-server twice as below. In this case, the app name is cook(spring.application.name=cook) and profile is not configured, thus `default` is being used as profile. 

2024-08-15T21:22:19.36+0900 [APP/PROC/WEB/0] OUT :: Spring Boot ::                (v3.3.2)
2024-08-15T21:22:19.50+0900 [APP/PROC/WEB/0] OUT 2024-08-15T12:22:19.498Z  INFO 19 --- [cook] [main] cook.CookApplication                     : Starting CookApplication v0.0.1-SNAPSHOT using Java 17.0.9 with PID 19 (/home/vcap/app/BOOT-INF/classes started by vcap in /home/vcap/app)
2024-08-15T21:22:19.50+0900 [APP/PROC/WEB/0] OUT 2024-08-15T12:22:19.501Z  INFO 19 --- [cook] [main] cook.CookApplication                     : No active profile set, falling back to 1 default profile: "default"
2024-08-15T21:22:19.57+0900 [APP/PROC/WEB/0] OUT 2024-08-15T12:22:19.575Z  INFO 19 --- [cook] [main] o.s.c.c.c.ConfigServerConfigDataLoader   : Fetching config from server at : https://config-server-###.###.###
2024-08-15T21:22:19.57+0900 [APP/PROC/WEB/0] OUT 2024-08-15T12:22:19.576Z  INFO 19 --- [cook] [main] o.s.c.c.c.ConfigServerConfigDataLoader   : Located environment: name=application, profiles=[default], label=null, version=null, state=null
2024-08-15T21:22:19.57+0900 [APP/PROC/WEB/0] OUT 2024-08-15T12:22:19.576Z  INFO 19 --- [cook] [main] o.s.c.c.c.ConfigServerConfigDataLoader   : Fetching config from server at : https://config-server-###.###.###
2024-08-15T21:22:19.57+0900 [APP/PROC/WEB/0] OUT 2024-08-15T12:22:19.576Z  INFO 19 --- [cook] [main] o.s.c.c.c.ConfigServerConfigDataLoader   : Located environment: name=cook, profiles=[default], label=null, version=null, state=null
2024-08-15T21:22:21.26+0900 [APP/PROC/WEB/0] OUT 2024-08-15T12:22:21.260Z  INFO 19 --- [cook] [main] o.s.cloud.context.scope.GenericScope     : BeanFactory id=3aa6cbf4-b3a3-333c-aa98-0ab8162b18ef
2024-08-15T21:22:21.81+0900 [APP/PROC/WEB/0] OUT 2024-08-15T12:22:21.816Z  INFO 19 --- [cook] [main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port 8080 (http)
2024-08-15T21:22:21.83+0900 [APP/PROC/WEB/0] OUT 2024-08-15T12:22:21.836Z  INFO 19 --- [cook] [main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2024-08-15T21:22:21.83+0900 [APP/PROC/WEB/0] OUT 2024-08-15T12:22:21.837Z  INFO 19 --- [cook] [main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.26]
2024-08-15T21:22:21.91+0900 [APP/PROC/WEB/0] OUT 2024-08-15T12:22:21.915Z  INFO 19 --- [cook] [main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2024-08-15T21:22:21.91+0900 [APP/PROC/WEB/0] OUT 2024-08-15T12:22:21.918Z  INFO 19 --- [cook] [main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2335 ms
2024-08-15T21:22:23.61+0900 [APP/PROC/WEB/0] OUT 2024-08-15T12:22:23.614Z  INFO 19 --- [cook] [main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port 8080 (http) with context path '/'
2024-08-15T21:22:23.65+0900 [APP/PROC/WEB/0] OUT 2024-08-15T12:22:23.652Z  INFO 19 --- [cook] [main] cook.CookApplication                     : Started CookApplication in 8.387 seconds (process running for 9.065)
2024-08-15T21:22:24.60+0900 [CELL/0] OUT Container became healthy


From the app logs, you will see the app fetches configuration twice 

  •  o.s.c.c.c.ConfigServerConfigDataLoader   : Located environment: name=application, profiles=[default] ...
  •  o.s.c.c.c.ConfigServerConfigDataLoader   : Located environment: name=cook, profiles=[default]

Environment

Spring Boot v3.0+

Cause

  • The Config Server fetches the default profile’s configuration first (under the application name) and then fetches the specific configuration for your application (cook).
  • This ensures that any common properties (from application.yml) are loaded first, followed by any specific overrides for cook from cook.yml.

Resolution

This behavior is normal and allows for layered configuration, where general properties (for all apps) are overridden by specific properties for each app. If you want to avoid multiple fetches, you can keep only one relevant configuration file.