2

I'm trying to use application properties, other than application.properties, say application_local.properties within resources directory.

So that I can have 2 properties files, one for local and other the server.

As mentioned in many blogs, I should use below command:

spring-boot:run -Dspring.config.location=/Users/myuser/work/MyProject/my-app/src/main/resources/application_local.properties

But this is not working, it is still fetching values from application.properties.

What am I missing, please suggest?

Thanks

sonic boom
  • 764
  • 4
  • 11
  • 26
  • It's clearly explained in spring docs: https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-external-config-profile-specific-properties – Raviteja Gubba Jan 13 '20 at 13:27

4 Answers4

8

1- Follow the naming convention application-{profile}.properties

  • application-local.properties

2-set profile

  • -Dspring.profiles.active=local

Briefly, you can use these two links:

  1. How to load property file based on spring profiles
  2. spring-profiles
4

-Dspring.profile.location takes directory as input. The purpose of this property is to specify additional directory location to keep your property files.

You are using property file name in your command.

Refer to detailed @ Answer at other thread here

Instead you can use as suggested by @mehardad

Rigz1213
  • 118
  • 1
  • 9
2

The -D option will send parameters to Java virtual machine. In order to send parameters to Spring boot, the command option of '--' must be used.

Example:

Suppose, there is an option named 'spring.profiles.active' defined in the application.properties file as follows:

spring.profiles.active=dev

This option can be overwritten using command line parameter as follows:

java -jar application.jar --spring.profiles.active=prod
Gopinath
  • 4,066
  • 1
  • 14
  • 16
1

Use Spring profiles and choose at runtime, locally would

-Dspring.profiles.active=local

The property file should be called application-local.properties

Beppe C
  • 11,256
  • 2
  • 19
  • 41