I'd like to avoid cluttering the application.properties
file with lots of things than, in my opinion, would be better in a separate file.
application.properties
should be something like
@include module1.properties
@include module1.properties
...
###################################
######### Spring Misc #############
###################################
# Direct log to a log file
logging.file=/tmp/kmp-manager.log
#local listening port
server.port=8082
spring.profiles=nr_dev nr_testing production
spring.profiles.active=production
spring.datasource.platform=postgresql
java.security.egd=file:/dev/./urandom
Is this at all possibile? If not, what would be a sane way to avoid cluttering?
In Spring property (or yaml) files we can reference other properties using the ${..} syntax.
properties” property file, as it was automatically built inside the Spring boot application when the project is initially created. We can create and maintain multiple property files within “Resources” module, where we will be able to define different types of property values in different files.
Just do not open the file in append mode. You read existing properties from the file and the write them again. If you append to the file, all the contents of the Properties object will be appended since this is what you asked for. FileOutputStream fileOut = new FileOutputStream(file,true);
Spring Boot Spring Boot 2.4 has added a feature for importing
We can now use spring.config.import=developer.properties
to import other file. Check this blog post for more details
It's possible in YML
file and the configuration are very simple
EXAMPLE:
To include properties of application-DATABASE.yml
file in application.yml
, use
spring:
profiles:
include: DATABASE
[EDIT - for 2.4.0 and above]
spring.profiles.group.prod=DATABASE
OR
Add the file name in application.properties
spring.config.import=classpath:application-DEV.yml,classpath:application-UDEV.yml,classpath:application-PRO.yml,classpath:application-SBA.yml
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