While I was scrolling through my twitter feed I noticed a post about the new Open Liberty 126.96.36.199 release on June 29. In the official blog post about the new release, they pointed out that Open Liberty now fully supports JavaEE 8 (JAX-RS 2.1, JPA 2.2, JSF 2.3 and so on ..) and that they offer a feature to run a typical Spring Boot application, packaged as an Uber-Jar, within Open Liberty. Right after I read the blog post I jumped into the first investigation about this feature. In this blog post, I'll share with you the result of my investigation.
To demonstrate this feature I implemented a simple Spring Boot (Java version: 1.8, Spring Boot version: 2.0.3.RELASE) based chat application makes use of Websockets, an in-memory H2 database, and a REST endpoint. The packaging version in the
In this blog post, I don't want to focus on the implementation of chat app. It's quite similar to the sample applications on the internet about Websockets with Spring. For the deployment within Open Liberty, you don't have to change or add code to your Spring application at any point (e.g.
Open Liberty server setup
For the deployment, you need the Open Liberty server on your local machine, which is available at (https://openliberty.io/downloads/). After downloading and extracting the zip file, navigate to the
wlpfolder and run
bin/server start defaultServer (use
bin/server.bat start defaultServer if you are running on Windows). Starting the
defaultServer for the first time, you will get a
usr/server/defaultServer folder within your
Now you have to open the
server.xml file within this folder and change it to the following if you are using my example application later on:
<?xml version="1.0" encoding="UTF-8"?>
<server description="new server">
If you are familiar with the configuration of Open Liberty/Websphere Liberty, you will notice the new feature
<feature>springBoot-2.0</feature>which is responsible for the correct deployment of our Spring Boot application. At the time of writing Open Liberty supports this feature for Spring Boot 1.5.X and 2.0.X applications. The already started defaultServer will receive the configuration changes and will update automatically (no restart needed).
In addition, I enabled the
websocket-1.1 feature to run my application because Open Liberty will use the Liberty web container instead of my embedded Tomcat. To effectively deploy the application Open Liberty offers several ways to this. I choose the explicit way where you have to a
<springBootApplication location=""/> section to your
server.xml to identify the app you want to deploy. In the
server.xml above, this section is already added.
Deploy the Spring Boot application to Open Liberty
Now you have to build your Spring application with Maven or Gradle and copy the build artifact to the
/apps folder within
wlp/usr/servers/defaultServer(make sure the name of your jar and the location reference in your
sever.xml match). Open Liberty will detect the deployment of the app and will start your Spring Boot application. The console log of your Spring application and the Open Liberty server is stored in
wlp/usr/servers/defaultServer/logs/console.log. The application is now available on http://localhost:9080. You can start chatting or get all chat messages from the REST endpoint at http://localhost:9080/api/messages.
Have fun deploying your Spring Boot application to Open Liberty,