Linux β€’ Web Apps & APIs

How to Create a Systemd Service for Java Spring Boot JAR

Spring Boot packages applications into executable fat JARs. Running Spring Boot under systemd allows you to configure JVM memory limits (`-Xmx`, `-Xms`), log redirection, and automated restarts.

/etc/systemd/system/spring-app.service
[Unit]
Description=Spring Boot Enterprise Service
After=syslog.target network.target

[Service]
Type=simple
User=spring
Group=spring
WorkingDirectory=/opt/spring-app
ExecStart=/usr/bin/java -Xms512m -Xmx2048m -jar app.jar --spring.profiles.active=prod
SuccessExitStatus=143
Restart=always
RestartSec=10
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target
Customize:
User:
WorkingDir:
ExecStart:

Systemctl Lifecycle & Journalctl Monitoring

sudo systemctl daemon-reloadRegister service
sudo systemctl enable --now spring-appStart Spring Boot JAR and enable on boot
sudo journalctl -u spring-app -fWatch live Spring Boot startup banner and logs

Linux & Systemd Production Best Practices

  • `SuccessExitStatus=143` tells systemd that Exit Code 143 (SIGTERM graceful shutdown in Java) is a planned success, not a service failure.

Frequently Asked Questions About Java Spring Boot Service

Frequently Asked Questions

Frequently Asked Questions

Everything you need to know regarding specifications, syntax, and security best practices.

Placing `application.properties` inside the `WorkingDirectory` (`/opt/spring-app/`) will cause Spring Boot to automatically load it with higher priority over internal JAR properties.