11

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?

Boris the Spider
  • 57,395
  • 6
  • 106
  • 161
Alienpenguin
  • 907
  • 9
  • 26
  • Looks like a [duplicate](https://stackoverflow.com/questions/25855795/spring-boot-and-multiple-external-configuration-files). Not importing but loading multiple files - does that answer your question? – Boris the Spider Sep 21 '16 at 12:09
  • Also, consider using [YAML](http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config-yaml) rather than `properties` - this gives a much more structured document. – Boris the Spider Sep 21 '16 at 12:11

2 Answers2

3

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

Niraj Sonawane
  • 8,519
  • 8
  • 64
  • 96
2

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
Thirumal
  • 5,736
  • 7
  • 40
  • 79
  • 2
    This seems to be possible in Spring Boot 2.4 now: https://spring.io/blog/2020/08/14/config-file-processing-in-spring-boot-2-4#importing-additional-configuration – a_horse_with_no_name Dec 04 '20 at 11:40