Add additional parameters to Spring Boot app

旧街凉风 提交于 2019-12-31 17:49:08

问题


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...


回答1:


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



回答2:


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




回答3:


Create a .conf file in the same directory with the same name as your executable jar e.g.

server-1.0-SNAPSHOT.jar server-1.0-SNAPSHOT.conf

JAVA_OPTS="-Xmx500m \
-Dspring.profiles.active=myprofile"

https://docs.spring.io/spring-boot/docs/current/reference/html/deployment-install.html#deployment-script-customization-conf-file



来源:https://stackoverflow.com/questions/31242291/add-additional-parameters-to-spring-boot-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!