Search code examples
javaspringspring-bootsystemd

Spring external config file does not load when start by systemd


I am developing and testing an Spring boot based java application.

I have the external config file "application.yml" stored in "config" folder which locates side-by-side with the corresponding jar file ("nlp-0.0.1-SNAPSHOT.jar") in the deployment server ( as per "24.3 Application property files")

and this is my "application.yml" file

---
 params:
   trustStorePath: config/client-truststore.jks
   trustStorePassword: wso2carbon
   keyStorePath: config/wso2carbon.jks
   keyStorePassword: wso2carbon
   defaultType: JKS
---
server:
   port: 9763
---

this works perfect as long as I start the application manually:

java -jar nlp-0.0.1-SNAPSHOT.jar

however, when I try to start the application by systemd command:

sudo systemctl start  nlp.service

the application starts up, yet the config file "application.yml" located in the "config" folder is not loaded

this is my "nlp.service" file

[Unit]
Description=NLP Service

[Service]
User=wjz
ExecStart=/usr/bin/java -jar /home/wjz/nlp-0.0.1-SNAPSHOT.jar
[Install]
WantedBy=multi-user.target

so, what is the problem? did I missed anything?


Solution

  • Maybe you should try to point option "WorkingDirectory" in your service. For example, if your app is located in /home/wjz/nlp-0.0.1-SNAPSHOT.jar and application.yml is located in /home/wjz/config so WorkingDirectory=/home/wjz/