While I was scrolling through my twitter feed I noticed a post about the new Open Liberty 220.127.116.11 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 about which I want to blog about today.
In this blog post, I don’t want to focus on the implementation of chat app because 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. pom.xml, application.properties etc.).
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 wlp folder 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 wlp folder.
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"> <featureManager> <feature>springBoot-2.0</feature> <feature>servlet-4.0</feature> <feature>websocket-1.1</feature> </featureManager> <httpEndpoint id="defaultHttpEndpoint" httpPort="9080" httpsPort="9443" /> <applicationManager autoExpand="true"/> <springBootApplication location="spring-boot-with-open-liberty.jar"/> </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 servlet-4.0 and 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.
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 and you can start chatting or get all chat message from the REST endpoint at http://localhost:9080/api/messages.
You can find the Spring Boot application on my GitHub repository if you want to try this on your machine.