Wanted to check if Spring boot offers help to use configuration file apart from application.properties
file. Ex: my-custom.properties file that can be profile specific,
ex:
my-custom-dev.properties
for dev profilemy-custom-uat.properties
for uat profileEdit: The question is that, I have the normal application-{env}.property file, apart from that, there are other property files in accord to their data content (ex: DB specific properties for logging, that I want to store in `db-log.properties, How would I make the other files profile sensitive?
In addition to application.properties files,
profile-specific properties can be defined with following convention: application-{profile}.properties.
The Environment has a set of default profiles (by default, [default]) that are used if no active profiles are set(In other words, if no profiles are explicitly activated, then properties from application-default.properties are loaded)
To run multiple profiles:
1.application-prod.properties
2.application-dev.properties
mvn spring-boot:run -Dspring-boot.run.profiles=dev,prod
3.application.properties (Default profile)
mvn spring-boot:run
4.Command Line Args with custom property files
spring.config.name - Set configuration files names(comma separated values) spring.config.location - Set the locations where Spring Boot will find your externalized configuration files.
java -jar hello-world.jar --spring.config.name=application,conf --spring.config.location=classpath:/external/properties/,classpath:/com/learn/../../
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-profiles.html
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config-profile-specific-properties
Additionaly to the application.properties
file, you can define as application-{profile}.properties
as you want.
The chosen file is determinated at launch, following the profile you have selected.
You can use it with active profile
@Configuration
@PropertySource("classpath:my-custom-${spring.profiles.active}.properties")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With