1

I want to set default profile=prod (when the project executes from the ci-cd on the server) and profile=local when I execute a project from intellij idea.

There is application.properties file:

spring.profiles.active=prod

#Database settings
spring.datasource.url=jdbc:mysql://localhost:3306/ddauth
...

There is application-local.properties file:

spring.datasource.url=jdbc:mysql://172.17.0.2:3306/ddauth

there is I set spring.profiles.active parameter in IntellijIdea Run configuration:

enter image description here

I also try to execute my jar file with a such parameter:

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

In any case, the project is executing in the prod mode. I receive following message during execution:

2023-08-01 23:02:52 [INFO] | AuthRunner:640 The following 1 profile is active: "prod"

I read many different tutorials and haven't any ideas how it has to work. I know I can set this profile parameter also in the bootJar task, but I don't want to go through this way. I want implement this simple solution and figured out why it isn't work.

Valentyn Hruzytskyi
  • 1,772
  • 5
  • 27
  • 59
  • Are you sure it needs to be `-D`? Can you try just `--spring.profiles.active=`? Also, for IDEA you can specify it directly as "Profile" field if you configure the module as a Spring project – Igor Artamonov Aug 01 '23 at 20:27
  • @IgorArtamonov thanks, but this option also doesn't work. I am a little bit confused...does it mean that I try the correct way but it doesn't work for me? Maybe the reason is the other? – Valentyn Hruzytskyi Aug 01 '23 at 20:30

1 Answers1

2

You need to pass -Dspring.profiles.active=local as a JVM argument.

Oliver
  • 1,465
  • 4
  • 17
  • Thanks, I haven't seen this possibility in my configuration but found here how to add it: https://stackoverflow.com/questions/50938383/how-to-set-jvm-arguments-in-intellij-idea – Valentyn Hruzytskyi Aug 01 '23 at 21:02
  • at first I was hella confused as I thought OP already passed `-Dspring.profiles.active=local`, but OP was passing it as a _program argument_ not _JVM argument_ – experiment unit 1998X Aug 02 '23 at 01:40