Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Running Spring Boot Apps Alone or in a Cluster

This guide explains what a standalone Spring Boot app is, what a cluster is, and how to run each one. It needs root access to a VPS or dedicated server.

General2 min read10 steps

Key words first

  • Java is a programming language.
  • Spring Boot is a toolkit that helps people build Java web apps quickly.
  • Standalone means the app carries its own small web server inside one file called a JAR. You do not need Tomcat installed on the side.
  • Cluster means running several copies of the app, so work is shared and one failure does not stop the site.

Run one standalone app

  1. Install Java on the server. Use the Java version your app was built for.
  2. Upload your JAR file with SFTP. Put it in a folder such as /opt/myapp.
  3. Test it.
    java -jar /opt/myapp/myapp.jar
    This starts the app. By default it listens on port 8080.
  4. Press Ctrl + C to stop it when the test is done.

Keep it running with systemd

systemd is the part of Linux that starts and restarts services.

  1. Create the file /etc/systemd/system/myapp.service with this text:
    [Unit]
    Description=My Spring Boot app
    After=network.target
    
    [Service]
    User=appuser
    ExecStart=/usr/bin/java -jar /opt/myapp/myapp.jar
    Restart=always
    
    [Install]
    WantedBy=multi-user.target
    This tells Linux how to run the app and to restart it if it stops.
  2. Load and start it.
    systemctl daemon-reload
    systemctl enable --now myapp
    This turns it on now and at every boot.

Build a cluster

  1. Run the same JAR on different ports, for example 8081 and 8082. Start each with --server.port=8081 and so on.
    java -jar myapp.jar --server.port=8081
    This sets the port for that copy.
  2. Put a load balancer in front. Nginx or Apache can do this job. A load balancer sends each visitor to a free copy.
  3. Do not store visitor sessions inside one copy. Use a shared store, such as a database or Redis, so any copy can serve any visitor.
  4. For several servers, run the same setup on each and point the load balancer at all of them.

Warning: Take a backup of your app and data before upgrading or moving it.

Tip: Run the app as a normal user, not root. Close its ports to the outside and let only the load balancer reach them.

Quick recap

  • A standalone app is one JAR that runs by itself.
  • Use systemd to start it and keep it alive.
  • A cluster is many copies behind a load balancer.
  • Share sessions so any copy can serve anyone.