bytor99999
bytor99999

Reputation: 991

How come application-<profile>.properties is not loading when profile is set?

I have application-dev.properties and application-local.properties in the root of my class path. Inside the properties files are my datasource properties. But they are not being loaded even though we start the app with

java -Dspring.profiles.active=local -jar myJarApp.jar

Thanks

Upvotes: 1

Views: 6539

Answers (3)

othmaann
othmaann

Reputation: 1

If you'd like to run it directly from maven

./mvnw spring-boot:run \
  -Dspring-boot.run.jvmArguments="-Dspring.profiles.active=PROFILE_NAME"

Example:

./mvnw spring-boot:run \
  -Dspring-boot.run.jvmArguments="-Dspring.profiles.active=dev"

Upvotes: 0

Julius
Julius

Reputation: 2864

Beware of hyphens in profile names.

In my case Spring Boot 2.3.2 would select the profile local-docker when running

java -jar -Dspring.profiles.active=docker target/main-0.0.1-SNAPSHOT.jar

But it would not select the associated properties file application-local-docker.properties for some reason. I reverted to using a profile name without hyphen and this works.

Upvotes: 0

Kartik Pandya
Kartik Pandya

Reputation: 2898

Try passing the argument as shown below:

$ java -jar xyz.jar --spring.profiles.active="dev"

Instead of using the -D flag.

Alternatively, you can set the following environment variable in your console/prompt, and then run the java -jar xyz.jar without passing any parameters

export SPRING_PROFILES_ACTIVE=dev

That should work.

Reference:

http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html

Upvotes: 2

Related Questions