Alternative option for passing profiles details for spring boot 2.2.4.RELEASE - spring-boot

When we try to run the jar file from the command prompt, we use "-Dspring.profiles.active=common,localhost".
But for >2.2 version we need to use "-Dspring-boot.run.profiles". What is the alternative option for jvm argument to run.
java -jar test.jar --spring.config.location=test.properties -Dspring-boot.run.profiles=localhost

Related

Use open telemetry in Spring boot without injecting the jar and using jvm args

I am testing opentelemetry in Spring boot and trying out if it is doable without injecting the jar file to the app and using jvm arguments, so far I tried using the following dependency in my gradle app:
runtimeOnly 'io.opentelemetry.javaagent:opentelemetry-javaagent:1.19.1'
and placed the the following properties in my application.properties file
otel.service.name=your-service-name
otel.traces.exporter=zipkin
but it's not working and traces are not showing in the console logs.
The OpenTelemetry javaagent is not able to extract configuration from the Spring config file; it happens way too late after the agent initialization.
You'll need to pass these settings either as system properties, e.g.:
java -javaagent:opentelemetry-javaagent.jar \
-Dotel.service.name=your-service-name \
-Dotel.traces.exporter=zipkin \
-jar my-app.jar
or as environment variables:
export OTEL_SERVICE_NAME=your-service-name
export OTEL_TRACES_EXPORTER=zipkin
java -javaagent:opentelemetry-javaagent.jar -jar my-app.jar

How to pass jvm arguments to spring boot deploy in tomcat?

I use spring boot package to jar, and run java -jar xxx.jar --logging.config=xxx.xml.
Now i package to war and deploy in tomcat, how can i pass logging.config such arguments?
I think these articles could be usefull for you:
https://www.middlewareinventory.com/blog/set-heapmemory-jvm-arguments-tomcat/
https://tomcat.apache.org/tomcat-8.5-doc/config/context.html
In a shorthand, there a two options. First one is to use tomcat global JAVA_OPTS:
Use Setenv.sh file to set JVM arguments to Tomcat instance
same as above, but using Catalina.sh
The example change is like:
JAVA_OPTS="-Xms1024m -Xmx1024m -Xss228k -XX:+UseParallelGC"
Verify your changes by executing ps -eaf|grep -i java command
Second one is to use Context from Tomcat. Please refer to the Context Parameters section of this document
If you are using gradle, you can do the following:
apply plugin: 'application'
applicationDefaultJvmArgs = ["-Xms2048m -Xmx4096m -XX:PermSize=256m -XX:MaxPermSize=512m -XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:+CMSIncrementalPacing -XX:CMSIncrementalDutyCycle=10 -XX:+UseParNewGC -XX:MaxGCPauseMillis=100 -XX:MaxGCMinorPauseMillis=50 -server -noverify -Xshare:off -Djava.net.preferIPv4Stack=false -XX:+EliminateLocks -XX:+UseBiasedLocking"]

Spring boot 2.0.4 application properties not being overridden by command line json

I am using spring boot 2.0.4 and creating an executable jar.
I have below properties defined in my application.properties
configserviceendpoint=devendpoint
I am following spring docs to pass the properties as .json and tried running the application using below commands
java -Dspring.application.json='{"configserviceendpoint":"prod end point"}' -jar myapp.jar
java -jar myapp.jar --spring.application.json='{"configserviceendpoint":"prod end point"}'
While trying to access the property in my code it still shows the value defined in application.properties and not the one which is being passed in command as .json
Thanks.
Please try to run it as following:
java -jar myapp.jar --configserviceendpoint="prod/endpoint"

How to generate executable scripts using spring boot maven plugin

Using spring boot maven plugin we are able to generate executable jars. And we can execute the jar using java -jar ...
In spring boot there is another option for installation . This generates the jar which can be added in init.d.
But is it possible to generate a sh|cmd file which can be used to start|stop|restart spring boot applications?
The executable true flag to create a 'fully executable’ jar actually pre-pends a shell script into the beginning of the jar.
It works outside init.d too. Try this:
./myapp.jar start

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