0

I'm working on a SpringBoot (2) application. I'm looking at our properties files which have become a bit convoluted and I'd like to tidy it a little.

In deployment we have a small main/resources/application.properties file which contains a few defaults and an external property file which contains a lot of other properties. This works well... and I'm trying to replicate this in dev and failing and I'm hoping I'm doing something silly which someone can point out painlessly.

As I understand it by default, Spring Boot will look in various places for the properties, in this order...

  1. classpath root
  2. /config in classpath
  3. in the current directory
  4. /config subdirectory of the current directory

Using Intellij I can't get SpringBoot to pick up 2 locations though. If I put all properties in main\resources\application.properties then that's fine. If I use -Dspring.config.name=dev and add a dev.properties with all properties this works well but I can't seem to configure a split in debug between defaults in main\resources\application.properties and a simulation of the external file somewhere else in the project (so that it won't get packaged in the jar).

Is there a simple way to do this, or any good documentation somewhere that I've missed that would explain it well enough that I might be able to simulate it in the dev environment ?

gringogordo
  • 1,990
  • 6
  • 24
  • 60
  • have you tried profiles? Many times in testing I have default values in src/main/resources and several test profile property files in src/test/resources. Then in the test I set the active profile (usually via an annotation in the test). In this manner, values from the default file are overridden by the active profile file. – John B Nov 01 '19 at 12:05
  • 1
    Possible duplicate of [How to load property file based on spring profiles](https://stackoverflow.com/questions/41263105/how-to-load-property-file-based-on-spring-profiles) – Abdelghani Roussi Nov 01 '19 at 12:07
  • Have a look at [this](https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-external-config) for properties order loading, However As @JohnB said, I think using profiles will be good for you – Abdelghani Roussi Nov 01 '19 at 12:09
  • So I don't really want to use profiles as I'd rather avoid anything quite so heavy handed for what is essentially standardising dev config. I think the reason I was confused is that I (and others) am using Intellij and others are using Eclipse (STS). In STS you can have default properties in main/resources/app.props and then extra props (simulating external) in config\app.props. One of the plugins merges them. Intellij just uses one or the other. Maybe there is a Spring plug-in which would simulate the STS behaviour so all devs can take the same approach ? – gringogordo Nov 04 '19 at 10:28

0 Answers0