Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
100 views
in Technique[技术] by (71.8m points)

java - 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.

question from:https://stackoverflow.com/questions/65601725/using-spring-profile-and-maven-profile

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...