Deploying a Spring Boot application to Liberty

You can enable Liberty to support a Spring Boot application.

About this task

To enable Liberty to support a Spring Boot application, add the springBoot-1.5 or springBoot-2.0 feature to the server.xml file. When you deploy a Spring Boot application, Liberty disables the web container that is embedded in the application and instead uses the Liberty web container. You can deploy one Spring Boot application for each server configuration.

The following steps use an example to show how to deploy a Spring Boot application. You create a Liberty server instance, deploy your Spring Boot .jar application, and specify the default HTTP port for the server instance. By default, Liberty deploys the Spring Boot application with the default host configuration. The example uses the hellospringboot.jar application and 9090 for the default HTTP port. If you don't have a Spring Boot .jar application, see the Spring Boot repository.

Procedure

  1. Run the server create helloserver command to create a server and name it helloserver.
    This command creates the /usr/servers/helloserver/apps directory.
  2. Enable the version of the Liberty springBoot feature that your application requires.
    For example, if your application uses Spring Boot 1.5.8, add the springBoot-1.5 feature to the featureManager element of the server.xml file.. If your application uses Spring Boot 2.0.1, enable the springBoot-2.0 feature. The hellospringboot.jar application uses the spring-boot-starter-web feature, which also requires you to enable a servlet feature.
    <!-- Enable features -->
    <featureManager>
      <feature>springBoot-1.5</feature>
      <feature>servlet-3.1</feature>
    </featureManager>
  3. Copy the hellospringboot.jar application into the /usr/servers/helloserver/apps directory that was created by the server create command.
  4. Choose to deploy an application with either the server.xml application configuration or with the dropins folder as shown in the following options.
    • Configure the application by updating the server.xml file that was created by the server create command.

      Define the application with a springBootApplication element or an application element.

      <springBootApplication location="hellospringboot.jar"/>
      <application type="spring" location="hellospringboot.jar"/>
    • If you choose not to update the server.xml file, use Liberty dropins support instead.
      • Copy the hellospringboot.jar file to the /usr/servers/helloserver/dropins/spring/hellospringboot.jar directory.
      • The spring subdirectory within the dropins subdirectory keeps the existing .jar or .war extension.
      • Use the .spring extension when you copy the application directly to the dropins subdirectory.
  5. Configure the HTTP port for the default host to 9090 by replacing the httpPort="9080" attribute value with an httpPort="9090" attribute value.
    <httpEndpoint id="defaultHttpEndpoint" host="*" httpPort="9090" />
  6. Start the server in the foreground.
    server run helloserver
  7. Test the application at the http://localhost:9090 URL.
  8. Optional: After you no longer need the server, run the server stop command.
    server stop helloserver