Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add additional parameters to Spring Boot app

I am wondering if it's possible to add spring's additional parameters such as -Dspring.profiles.active=prod to spring boot app in case of running it as a service.

I checked the script that was generated automatically by spring-boot-maven-plugin:

command="$javaexe -jar -Dsun.misc.URLClassPath.disableJarChecking=true $jarfile $@"

so maybe it can be done via maven plugin's options, but couldn't find any except of JVM arguments which is not so useful...

like image 558
nKognito Avatar asked Jul 06 '15 09:07

nKognito


People also ask

Can we have multiple application properties in spring boot?

Spring Boot supports different properties based on the Spring active profile. For example, we can keep two separate files for development and production to run the Spring Boot application.

Can we have more than one @springbootapplication?

In this example we are having two SpringBoot applications that we want to merge into one and for that we will create a new SpringBoot application for package them both and add the two old applications as maven dependencies. Then we will ask Spring to boot-up the application.


2 Answers

I couldn't find any solution including the one I described in question - it seems that plugin's additional params also don't work.

At the end I solved it by using systemd service approach.

Looks like that and works perfectly:

[Unit]
Description=Some app
After=syslog.target

[Service]
ExecStart=java -Dspring.profiles.active=production -jar /home/apps/monitoring-app-1.0.0.jar

[Install]
WantedBy=multi-user.target
like image 76
nKognito Avatar answered Sep 21 '22 18:09

nKognito


You can use external configuration file for example.

Based on the documentation if you provide an application.properties file in the ./config directory next to the executed jar you can set up the active profile through that properties file.

Just use spring.profiles.active=myprofile in ./config/application.properties

http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config-application-property-files

http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html

like image 40
László Szabó Avatar answered Sep 20 '22 18:09

László Szabó