Defining Spring Boot application arguments

You can deploy a Spring Boot application to Liberty and configure the arguments to override the application property defaults.

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 helloserver server configuration with the enabled Liberty features that are necessary to support the Spring Boot application.

About this task

When you start the executable JAR file, you start a Spring Boot application with a list of command line arguments.
java -jar hellospringboot.jar --server.context-path=/mypath --myapp.arg=true
By default, the SpringApplication Spring Boot class converts any command line argument that starts with dashes (--) to a property and adds it to the Spring Environment.
--server.context-path=/mypath

When you deploy a Spring Boot application to Liberty, you can configure the command line argument for the application with the applicationArgument element within the springBootApplication element. Use these elements when you want to override application property defaults that are included in the Spring Boot application.

In the example, the hellospringboot.jar Spring Boot application deployment to Liberty is configured to pass multiple command line arguments. The two properties that are used in the example are the Spring Boot 1.5 application properties for configuring the server.context-path context path and the server.servlet-path Spring dispatcher servlet path.

For more information, see Spring Boot 1.5.x common application properties.

Procedure

  1. Find the springBootApplication element in the server.xml file of an existing helloserver server.
    <springBootApplication location="hellospringboot.jar"/>

    For this example, the springBootApplication element includes the hellospringboot.jar application.

  2. Add a command line argument for the application with the applicationArgument element and pass the --server.context-path=/testpath1 argument to change the context root to /testpath1.
    <springBootApplication location="hellospringboot.jar">
        <applicationArgument>--server.context-path=/testpath1</applicationArgument>
    </springBootApplication>
  3. Start the server in the foreground.
    server run helloserver
  4. Test the application at the http://localhost:9090/testpath1 URL.
  5. Without stopping the server, change the context path to testpath2.
    <springBootApplication location="hellospringboot.jar">
        <applicationArgument>--server.context-path=/testpath2</applicationArgument>
    </springBootApplication>

    The Spring Boot application stops and restarts with the new context path.

  6. Test the application at the http://localhost:9090/testpath2 URL.
  7. Without stopping the server, add an application argument with the applicationArgument element.
    <springBootApplication location="hellospringboot.jar">
        <applicationArgument>--server.context-path=/testpath2</applicationArgument>
        <applicationArgument>--server.servlet-path=/mydispatcher</applicationArgument>
    </springBootApplication>

    The Spring Boot application stops and restarts with the same context path.

  8. Test the application at the http://localhost:9090/testpath2/mydispatcher URL.