Reputation: 13533
I'm running into this strange issue where I can run my Spring Boot application without problems from within Intellij, but when I do:
mvn clean package -Pst -Dspring.profiles.active=st && java -jar target/myapp-0.0.1-SNAPSHOT.jar
I can see errors saying Spring Boot cannot resolve the @Value placeholders.
ERROR o.s.boot.SpringApplication - Application startup failed
java.lang.IllegalArgumentException: Could not resolve placeholder
What I did to investigate was to get the jar file and extract the files like using jar xf myapp.jar
and I can see the properties files in the classpath root. Initially I had this problem that Maven was not packaging my properties and statics from the main/resource
folder, but I already resolved that with:
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>static</directory>
<targetPath>static</targetPath>
</resource>
Any comments, ideas what could I be missing here?
Upvotes: 1
Views: 3788
Reputation: 1
It is not Maven deciding, what Spring Profile you use, but the Spring container during every single execution of the jar. The differen profiles are all available. The Spring profile is used to adapt the executable to different environments by configuration.
There are additionally Maven profiles, but they configure the build of the executable, not the execution.
Upvotes: 0
Reputation: 13533
I managed to resolve this. It was really weird, it seems that I need to tell java in which profile to run the jar in e.g --spring.profiles.active=st.
mvn clean package -Pst -Dspring.profiles.active=st && java -jar target/myapp-0.0.1-SNAPSHOT.jar --spring.profiles.active=st
Upvotes: 2