Confuse of run Spring boot 1.3.0 application and specify certain profile - spring-boot

When I use spring boot 1.3.0 rc1, when run application by
mvn spring-boot:run
in console it will output
no profile actived
when you run application with
mvn spring-boot:run -Dspring.profiles.active=test
in console, in will output
profile test are activated
But yesterday when I changed to 1.3.0 release and run application in production,
java -Dspring.profiles.active=production -jar myapp.jar
I can't find above output in console.
In addition, I think it will only load appication-production.properties if you specified production profile, but it not, it still load application.properties.
So all these let me feel confuse and mislead me think prodcution profile cannot effect and run application by this way that is java -jar your.jar could not support -Dspring.profiles.active, meantime my colleague waiting for using my service so it give me many pressure.
Can anyone could explain it ?

Related

Is there any meaning to running -Dspring.profiles.active=dev,runtime when running Spring Boot locally?

In my team I frequently (>10) see Spring Boot projects with the following instructions for running locally:
mvn clean spring-boot:run -Dspring.profiles.active=dev,runtime
My understanding of Spring Boot profiles is that each one corresponds to a particular environment, eg dev, test - so you would never need more than one. Also that each profile name corresponds to a particular env file - eg src/main/java/resources/application-dev.yml application-test.yml etc.
I would have thought that you would run the app on your local machine with:
mvn clean spring-boot:run -Dspring.profiles.active=local
And have the local configuration in:
src/main/java/resources/application-local.yml
This is running:
Java 11
maven parent is org.springframework.boot spring-boot-starter-parent 2.2.6.RELEASE
maven version is 3.3.9
My question is: Is there any meaning to running -Dspring.profiles.active=dev,runtime when running Spring Boot locally?

Running Spring Boot Application.main() via IntelliJ doesn't find my local profile

I've been running my Spring Boot (2.1.0) app via Gradle bootRun but since adding in the Actuator, this causes the app to not actually shutdown when I tell IntelliJ to stop the app. For whatever reason, this is only an issue when running in Debug mode.
The solution I found online was to just run the Application.main() but now, my local profile isn't being picked up. So I have the typical application.yml along with various other profiles. All of the developers have an application-local.yml that is sitting at the root of the project and is ignored by git. Running Gradle's bootRun with local as the active profile works. But running Application.main() with the local active profile does not pick up the application-local.yml file's config.
As you can see in the image, I've not only specified the profile in Intellij's Active profiles section, but also as a VM option just like I do when running via Gradle.
One more thing which you can try
Set spring.profiles.active=local in Environment Variables below VM Options

Running springboot using maven vs. via java directly?

Essentially, the Jenkins CI job runs mvn spring-boot:run .... in a productions cluster as the only way to run the application. With this build step, in effect, we are running the springboot app only via maven and this has led to a very unstable jvm behavior. Also, I am unable to configure all the possible tweaks to the jvm e.g, turning on gc logging or changing to G1GC etc.. etc..
I just wanted to know if running my java springboot app should indeed be packaged into a fat jar and run with standard jvm flags, rather than from maven.
Please let me know your thoughts
Spring boot maven plugin has jvmArguments in order to set jvm settings.
......
<configuration>
<jvmArguments>-Xdebug</jvmArguments>
</configuration>
.......
The second option is to create a self-executable jar/war and use a standard way to run app - java -jar app.jar <jvm properties>
Our teams have been running fat jars similar to how others have stated with the simple java -jar ****.jar commands. However, once in production, you can utilize a container clustering system to construct the many microservices that make up your app. Seems like running maven and deploying source code, rather than artifacts seems dangerous. Hopefully this helps!

tomcat7-maven-plugin to deploy spring boot with appropriate spring profile selected

My goal is to be able to use the tomcat-maven plugin to deploy my spring boot application from the command line where an argument is supplied that tells spring which profile to use like this:
mvn tomcat7:deploy -Dspring.profiles.active="dev"
I've tried several different things such as the solution described here but the default application.properties is still always selected.
The only way that I've been able to get the application-dev.properties selected is by using
mvn spring-boot:run -Dspring.profiles.active="dev"
But we don't want to have tomcat packaged in our war
I'm new to maven and spring boot and I've been spinning my wheels for the better part of a a day now so any advice would be appreciated.
Consider using MAVEN_OPTS environment variable to set VM argument. (Linux/osx) example you would need to execute before your maven goal:
export MAVEN_OPTS="-Dspring.profiles.active=dev"
I found out the issue and I was able to get the correct profile selected using
export SPRING_PROFILES_ACTIVE=dev. The problem that I was having was when I was starting my local tomcat server through the eclipse UI my environment variables were being ignored. When starting tomcat through startup.bat the environment variable gets used and spring uses the correct profile.

how to tune jvm when using spring boot application as unix service

i'm using the new spring-boot 1.3.0 feature to run tomcat embedded spring-boot application jar as a unix service.
All is working fine but i don't know how to tune jvm (with -Xms and -Xmx parameters for example)
I've searched in spring documentation and around the web without success.
It's missing from the documentation (I've opened an issue to correct that), but you should be able to use the JAVA_OPTS environment variable.
You can configure it in a .conf file that's situated next to the jar. For example, if you jar file is /var/myapp/myapp.jar, the file /var/myapp/myapp.conf will be sourced by the launch script.
There is one more option to achieve the same , if you are running jar with mvn you can do something like this
mvn spring-boot:run -Drun.jvmArguments="-Xmx512m"
And If you are running with java -jar ,you can try something like this
java -Xmx1G -jar myapp.jar

Resources