Defining Spring Boot application arguments
We can deploy a Spring Boot application to Liberty and configure the arguments to override the application property defaults.
For the most current information about deploying Spring Boot applications to Liberty, see the Open Liberty website.
Install an existing helloserver server configuration with the enabled Liberty features that are necessary to support the Spring Boot application. 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 we deploy a Spring Boot application to Liberty, we can configure the command line argument for the application with the applicationArgument element within the springBootApplication element. Use these elements when we want to override application property defaults 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 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.
See Spring Boot 1.5.x common application properties.
- 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.
- 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>
- Start the server in the foreground.
server run helloserver
- Test the application at the http://localhost:9090/testpath1 URL.
- 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.
- Test the application at the http://localhost:9090/testpath2 URL.
- 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.
- Test the application at the http://localhost:9090/testpath2/mydispatcher URL.