This Spring Boot application is a sample project specifically designed to demonstrate property overriding behavior in a Spring Boot configuration.
The purpose of this application is to show the specifics of the properties overriding mechanism in a Spring Boot project.
ApplicationPropertiesHolder
class maps its fields to corresponding properties to be loaded from different property sources. The expectation is, while each property/field is defined in eitherapplication.properties
orapp.properties
, both should be overridden by same-name values inoverride.properties
.AdditionalConfigurationFilesAdder
class adds additional property sources to the application's environment. The added sources will override values defined inapplication.properties
including profile-specificapplication-*.properties
.Application
class serves as the entry point of the application.
To run the project, follow these steps:
- Ensure that you have Java and Maven installed on your system.
- Clone the repository and navigate to the project directory.
- Build the project using the command:
mvn clean install
- Run the application using the command:
mvn test
application.properties
: defines theapplication
field in theApplicationPropertiesHolder
class.app.properties
: defines theapp
field in theApplicationPropertiesHolder
class.override.properties
: overrides bothapp
andapplication
properties.
The PropertiesConfigTest
class includes two test methods:
definedInAppProperties()
: verifies that the value of theapp
- property is overridden as expected according to
override.properties
. definedInApplicationProperties()
: asserts that the value of theapplication
property is overridden according tooverride.properties
.
The specifics of Spring Boot property overriding behavior discussed on GitHub and on StackOverflow:
- @PropertySource not overriding in order [SPR-13500] - in a comment by Maksim Muruev (mmuruev).
- How to override application.properties during production in Spring-Boot? - in a comment by Alexander Vasiljev.
- @PropertySource doesn't override properties defined in application.properties - My question and an answer to it that helped to build this solution. Thanks to M. Deinum from Netherlands