How to resolve Spring Boot configuration override issues when deploying microservices
Purpose
This post demonstrates how to resolve unexpected configuration overrides in Spring Boot applications.
When I deploy multiple microservices, I got this problem:
product-service@[root]# java -jar target/product-service.jar2026-02-22 10:15:45,123 INFO [main] o.s.b.SpringApplication - Starting ProductService2026-02-22 10:15:45,456 INFO [main] o.s.c.a.ConfigurationClassPostProcessor - Identified candidate configuration class: com.example.ProductServiceApplication2026-02-22 10:15:46,789 WARN [main] o.s.b.a.ApplicationAvailabilityBean - Application availability state was not set prior to marking as available2026-02-22 10:15:47,012 INFO [main] o.s.b.SpringApplication - Started ProductService in 1.532 seconds (JVM running for 2.123 seconds)2026-02-22 10:15:47,345 ERROR [main] o.s.beans.factory.BeanCreationException - Error creating bean with name 'appProperties': Could not resolve placeholder 'app.feature.enabled' in value "${app.feature.enabled}"But my application.yml file clearly has the property:
server: port: 8080
app: feature: enabled: true name: "product-service"
management: endpoints: web: exposure: include: health,infoEnvironment
- Spring Boot 3.2.1
- Java 21
- Maven 3.9.0
- Ubuntu 22.04 LTS
What happened?
I tried to deploy multiple Spring Boot services and noticed something strange. One service’s configuration was affecting another service, even though they had separate configuration files.
I can explain the key parts:
- Each service has its own
application.ymlfile - Services use different profiles for different environments
- Properties should be isolated between services
But when I run the product service, I got this error:
product-service@[root]# java -jar target/product-service.jarError creating bean with name 'appProperties': Could not resolve placeholder 'app.feature.enabled' in value "${app.feature.enabled}"The application starts but fails to bind my configuration properties.
How to solve it?
I tried to debug by adding logging to see where Spring Boot is reading configuration from:
spring: main: log-startup-info: true banner-mode: "console" config: import: "classpath:application.yml,classpath:application-*.yml"
logging: level: org.springframework.context.support.PropertySourcesPlaceholderConfigurer: DEBUGThen I ran the application again:
product-service@[root]# java -jar target/product-service.jar2026-02-22 10:20:15,123 DEBUG [main] o.s.c.support.PropertySourcesPlaceholderConfigurer - Found 2 property sources:1. CommandLinePropertySource [name: commandLineArgs]2. MapPropertySource [name: applicationConfig: [classpath:/application.yml]]I can see that Spring Boot only found the configuration file I explicitly imported, but missed the profile-specific configurations.
So I modified the configuration to use proper profile activation:
server: port: 8080
spring: profiles: active: dev
app: feature: enabled: true name: "product-service"And created a profile-specific configuration:
app: feature: enabled: false # Override for dev environment name: "product-service-dev"
logging: level: com.example: DEBUGNow test again:
product-service@[root]# java -jar target/product-service.jar2026-02-22 10:25:15,123 DEBUG [main] o.s.c.support.PropertySourcesPlaceholderConfigurer - Found 4 property sources:1. CommandLinePropertySource [name: commandLineArgs]2. MapPropertySource [name: applicationConfig: [classpath:/application-dev.yml]]3. MapPropertySource [name: applicationConfig: [classpath:/application.yml]]4. MapPropertySource [name: defaultProperties]
2026-02-22 10:25:16,456 INFO [main] o.s.b.SpringApplication - Started ProductService in 1.456 secondsYou can see that I succeeded to load all configurations with proper precedence.
The reason
I think the key reason for the configuration override issues is the property precedence hierarchy in Spring Boot:
- Highest Priority: Command line arguments (
--property.name=value) - Environment variables: System properties (
SERVER_PORT=8080) - External configuration: Files specified via
spring.config.location - Application YAML/properties:
application.ymlorapplication.properties - Profile-specific configs:
application-{profile}.yml - Default values: Properties in
@ConfigurationPropertiesor@Valueannotations
The problem occurs because later sources override earlier ones. When I didn’t properly configure profile activation, Spring Boot loaded configurations in the wrong order, causing overrides to happen unexpectedly.
Here’s how I verify the precedence order:
@SpringBootApplicationpublic class ConfigOrderChecker { public static void main(String[] args) { ConfigurableApplicationContext context = SpringApplication.run(ConfigOrderChecker.class, args);
String[] sources = context.getEnvironment().getPropertySources().stream() .map(PropertySource::getName) .toArray(String[]::new);
Arrays.stream(sources).forEach(System.out::println); }}Summary
In this post, I showed how to resolve Spring Boot configuration override issues by understanding the precedence hierarchy. The key point is that Spring Boot follows a strict order when loading configuration properties, and profile-specific configurations take precedence over default ones but are overridden by command-line arguments.
To prevent unexpected overrides:
- Always set
spring.profiles.activein your main configuration - Use profile-specific files for environment-specific settings
- Be aware that command-line arguments have the highest priority
- Check the property sources order when debugging configuration issues
Final Words + More Resources
My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me
Here are also the most important links from this article along with some further resources that will help you in this scope:
- 👨💻 Spring Boot Official Documentation - Externalized Configuration
- 👨💻 Spring Boot Property Precedence Guide
- 👨💻 Reddit: Spring Boot Configuration Issues
Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!
Comments