Configuring thin Spring Boot applications

You can thin a Spring Boot application to create efficient Docker layers and use resources efficiently.

Open Liberty For the most current information about deploying Spring Boot applications to Liberty, see the Open Liberty website.

Before you begin

Install an existing Spring Boot 1.5 application WAR or JAR file, helloSpringBootApp.jar, that you want to thin and deploy to a Liberty server. You also need an existing helloserver server configuration with enabled Liberty features that are necessary to support the Spring Boot application.

About this task

A Spring Boot application JAR or WAR file is a self-contained artifact. It packages all of the application dependencies inside the final artifact alongside the application content, including an embedded server implementation, such as Tomcat, Jetty, or Undertow. The result is a fat artifact that is easy to run on any server that has a JVM. It also results in a large artifact, even for the smallest hello world Spring Boot web application.

With a microservices architecture, the application content included in a Spring Boot application JAR file can be small and likely much smaller than the Spring Boot framework dependencies. A large application JAR file can become costly to deploy if your application needs frequent updates. For example, if you use Docker to deploy your application to the cloud, you need to build a new Docker layer that includes your updated application content. This new Docker layer contains the updated fat JAR file, which contains both your application content and all of the Spring Boot framework dependencies, resulting in large Docker layers for updating your application in the cloud.

Liberty can create efficient Docker layers for your application updates and use resources efficiently when you deploy frequent updates to your microservice applications in the cloud.

Liberty uses the springBootUtility command to separate the Spring Boot application content from the dependencies that are packaged inside of the Spring Boot application, thinning the Spring Boot application. For command line options, see the springBootUtility command.

Procedure

  1. Configure the thin Spring Boot application JAR file and the library dependencies.
    1. Deploy the thin Spring Boot application JAR file like a fat Spring Boot application as explained in Deploying a Spring Boot application to Liberty.
    2. Deploy the library dependencies to the usr/shared/resources/lib.index.cache/ directory.
  2. Invoke the springBootUtility command with the necessary options to create the thin Spring Boot application in the correct dropins folder of the helloserver server configuration and to cache the dependencies to the usr/shared/resources/lib.index.cache directory.
    <wlp>/bin/springBootUtility thin \
        --sourceAppPath=hellospringboot.jar \
        --targetLibCachePath=<wlp>/usr/shared/resources/lib.index.cache \
        --targetThinAppPath=<wlp>/usr/servers/helloserver/dropins/spring/hellospringboot.jar
  3. Start the server with the server run helloserver command.
  4. Test the application at the http://localhost:9080 URL.
    The default HTTP endpoint is used to service the application.