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

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"

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

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

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

How to Run the spring boot jar

I have spring boot jar. It contains boot-inf folder with that folder it contains classes and lib folder. I need to run the certain class which is having main method. But I don't know how to run it. For normal jar we can use the below format to run the class from the jar.
java -cp "sample.jar;dependecy.jar" com.sample.ClassName
But in spring boot jar what is the format to run the class. Because it contains boot-inf folder. I am using gradle script to build the project
It should be very easy, just:
java -jar sample.jar
where sample.jar is your spring boot jar.
See https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-running-your-application.html
You can try with the distribution to run the class in a jar. Build the project to create the dist. Then you can run the class as you mentioned in the question.
java -cp "sample.jar;dependecy.jar" com.sample.ClassName

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