Rishabh Toki
Rishabh Toki

Reputation: 58

Using Spring profile and Maven Profile

I am now to Spring profile and I have a question, if I am doing a environment specific build using maven like mvn -Ptest then do I need to provide SPRING_PROFILES_ACTIVE parameter on execution.

If I understand Spring Profile correctly, giving SPRING_PROFILES_ACTIVE will direct my spring boot application to pick up the necessary application properties/@profile beans then why do I need to do mvn -Ptest.

One point I came accross is that mvn -Ptest allows us to package our properties file accordingly but in that case, isnt using Spring Profile a better solution.

It will be great if someone can point any scenario wherein we have to use mvn -Ptest even if we are using spring profile in Java application.

Upvotes: 0

Views: 503

Answers (1)

Deadron
Deadron

Reputation: 5289

I think you are confusing maven profiles with spring profiles.

Maven profiles allow you to execute builds with different build configurations. It is only used during the maven build process.

Spring profiles can allow you to load different property files and is available at runtime to do whatever you want.

Now, you may have a maven profile that executes your spring application with a spring profile set but the difference is build vs execution time.

Upvotes: 1

Related Questions