Deployment

A Spring Bot application can be deployed in several ways:

  1. Standalone plain Java application - One single Jar (FatJar)
  2. Standalone executable on Unix - as first but with shell script included
  3. Deployment as a WAR file
  4. Cloud, i.e., Heroku, Cloud Foundry

In its bare essence, a Spring Boot application is a plain Java application with a main method. As long as all the dependency are met, it can run.

Build a Standalone FatJar

This is the simplest deployment variant, as we do not have to set up anything at all. By using the Spring Boot Maven Parent, we already get a configured version of the Spring Boot Maven Plugin. So, whenever we run mvn package or mvn install, Spring Boot will build a single FatJar file with all the dependencies included. It’s in the target folder.

Start it with:

java -jar comment-store-1.0.0-SNAPSHOT.jar

It will start the application as during implementation with the difference now, that everything is included in this single file.

Build an Executable FatJar

In short, we need to reconfigure the Spring Boot Maven Plugin like:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <executable>true</executable>
    </configuration>
</plugin>

It will now add a starting shell script at the beginning of the Jar file. The script is compatible with init.d.

More in Spring Boot: How To Get Started and Build a Microservice

Deploy to the Cloud

The application is still built as a FatJar, but instead of running on your own server or virtual server, we put the build artifact to a cloud provider.

See instructions for: