Skip to content

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:

Terminal window
product-service@[root]# java -jar target/product-service.jar
2026-02-22 10:15:45,123 INFO [main] o.s.b.SpringApplication - Starting ProductService
2026-02-22 10:15:45,456 INFO [main] o.s.c.a.ConfigurationClassPostProcessor - Identified candidate configuration class: com.example.ProductServiceApplication
2026-02-22 10:15:46,789 WARN [main] o.s.b.a.ApplicationAvailabilityBean - Application availability state was not set prior to marking as available
2026-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:

src/main/resources/application.yml
server:
port: 8080
app:
feature:
enabled: true
name: "product-service"
management:
endpoints:
web:
exposure:
include: health,info

Environment

  • 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.yml file
  • Services use different profiles for different environments
  • Properties should be isolated between services

But when I run the product service, I got this error:

Terminal window
product-service@[root]# java -jar target/product-service.jar
Error 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:

src/main/resources/application.yml
spring:
main:
log-startup-info: true
banner-mode: "console"
config:
import: "classpath:application.yml,classpath:application-*.yml"
logging:
level:
org.springframework.context.support.PropertySourcesPlaceholderConfigurer: DEBUG

Then I ran the application again:

Terminal window
product-service@[root]# java -jar target/product-service.jar
2026-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:

src/main/resources/application.yml
server:
port: 8080
spring:
profiles:
active: dev
app:
feature:
enabled: true
name: "product-service"

And created a profile-specific configuration:

src/main/resources/application-dev.yml
app:
feature:
enabled: false # Override for dev environment
name: "product-service-dev"
logging:
level:
com.example: DEBUG

Now test again:

Terminal window
product-service@[root]# java -jar target/product-service.jar
2026-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 seconds

You 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:

  1. Highest Priority: Command line arguments (--property.name=value)
  2. Environment variables: System properties (SERVER_PORT=8080)
  3. External configuration: Files specified via spring.config.location
  4. Application YAML/properties: application.yml or application.properties
  5. Profile-specific configs: application-{profile}.yml
  6. Default values: Properties in @ConfigurationProperties or @Value annotations

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:

src/main/java/com/example/ConfigOrderChecker.java
@SpringBootApplication
public 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:

  1. Always set spring.profiles.active in your main configuration
  2. Use profile-specific files for environment-specific settings
  3. Be aware that command-line arguments have the highest priority
  4. 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:

Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!

Comments