0

I need two application.properties in my Spring Boot App.

I know that using the annotation @PropertySource I can specify more than 1 property files.

I tried to use: @PropertySource({"classpath:application.properties","classpath:external.properties"})

The idea of it is having application.properties with the machine independent properties and this file will be included inside the war file.

The other file (external.properties), will leave in the machine, and won't be included in the war file. Here I want to leave properties like the database connection and so on.

I've already changed catalina.properties for adding the external.properties location into the classpath, but unfortunately when running on Eclipse it doesn't work (complains about the missing database properties.).

  • So, you don't want to add external.properties under src folder? Am I understanding it right? Can you try adding it in Properties -> Java Build Path -> Link Source in Eclipse? – Gayatri Jul 15 '19 at 16:48

1 Answers1

0

If the external properties file will be available in a known location on the machine, then have an environment variable, system property, or command-line argument set up with the path to the file. Then, reference the file in you @PropertySource annotation using file: rather than classpath:

Example: @PropertySource("file:${CONF_DIR}/external.properties")

References: Spring boot docs on external configuration

PropertySource documentation

Blog post regarding PropertySource

user506069
  • 771
  • 1
  • 6
  • 14