Skip to content

Commit

Permalink
Apply review suggestions from @dmuelle
Browse files Browse the repository at this point in the history
Co-authored-by: David Mueller <[email protected]>
  • Loading branch information
scottkurz and dmuelle committed Apr 29, 2024
1 parent e69b0ff commit 642559f
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions posts/2024-05-01-spring-boot-3.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@ Scott Kurz <https://github.com/scottkurz>

As of version 23.0.0.9, Liberty offers support for Spring Boot 3.1, allowing developers to take advantage of the Spring and Spring Boot libraries while providing a range of https://openliberty.io/blog/2022/10/17/memory-footprint-throughput-update.html[performance] enhancements specifically engineered to provide an industry-leading, first-class platform for Spring Boot applications.

When packaging a Spring Boot app in the WAR format, developers and administrators get to choose from two Liberty deployment options, each with a different set of advantages.
When you package a Spring Boot app in the WAR format, you can choose from two Liberty deployment options, each with a different set of advantages.

A Spring Boot WAR can simply be deployed like any standard Jakarta EE WAR using the same developer tooling and server configuration, and providing a common DevOps workflow as with your other Liberty WAR deployments.
You can deploy a Spring Boot WAR like any standard Jakarta EE WAR by using the same developer tooling and server configuration, and providing a common DevOps workflow with your other Liberty WAR deployments.

In addition, with Liberty, you can use a special https://openliberty.io/docs/latest/deploy-spring-boot.html[optimized deployment for Spring Boot applications]. The optimization adds some configuration options and provides advantages for efficiently building Docker container images by using some extra `pom.xml` and `server.xml` file configuration.
Alternatively, you can use a special https://openliberty.io/docs/latest/deploy-spring-boot.html[optimized Liberty deployment for Spring Boot applications]. This optimization adds some configuration options and provides advantages to efficiently build Docker container images.

In this blog post, we'll first create a simple app by using the link:https://start.spring.io/[Spring Initializr], and then deploy it as a WAR to Liberty without any modifications, using the same deployment as for any WAR.

We then show how to optimize the Spring Boot deployment by adding the Liberty Maven Plugin (`liberty-maven-plugin`) and a simple `server.xml` configuration with the `springBoot-3.0` feature. We can then build an efficiently-layered Docker image.
We then show how to optimize the Spring Boot deployment by adding the Liberty Maven Plugin (`liberty-maven-plugin`) and a simple `server.xml` configuration with the `springBoot-3.0` feature. We can then build an efficiently-layered Docker image.


== Prerequisites
- The sample requires Java 21 (though it could be easily reworked using Java 17)
- The sample requires Java 21 (though you could be easily rework it to use Java 17)

== Deploy as standard WAR
== Option 1: Deploy your Spring Boot app as standard WAR file

1. Create a project from your browser using link:https://start.spring.io/#!type=maven-project&language=java&platformVersion=3.2.5&packaging=war&jvmVersion=21&groupId=demo&artifactId=spring-liberty&name=spring-liberty&description=Demo%20project%20for%20Spring%20Boot&packageName=demo&dependencies=web[this Spring Initializr configuration].
+
2. Add the following Spring web controller file (use the `vi` command here, or your preferred editor) :
2. Add the following Spring web controller file (use the `vi` command here, or your preferred editor).
+
[source,sh]
----
Expand Down Expand Up @@ -84,7 +84,7 @@ The app is deployed in dev mode, like you would with any Jakarta EE WAR, without

The Spring portion of the app is bootstrapped by the web container by using the `SpringBootServletInitializer` extension generated into your application by the **Spring Initializr** and from there you can use the Spring and Spring Boot APIs.

== Use optimized Liberty Spring Boot deployment
== Option 2: Use the optimized Liberty Spring Boot deployment

This example uses the same Spring app that is created in step 1 of the previous example. By adding some extra configuration in the `pom.xml` and `server.xml`, you can build an efficiently-layered Docker image and also parameterize the app with application arguments.

Expand All @@ -103,7 +103,7 @@ This example uses the same Spring app that is created in step 1 of the previous
</plugin>
----
+
2. Create your Liberty `server.xml` file by copying from the Spring Boot template
2. Create your Liberty `server.xml` file by copying from the Spring Boot template.
+
[source,sh]
----
Expand All @@ -112,7 +112,7 @@ mkdir -p src/main/liberty/config/
cp target/liberty/wlp/usr/servers/defaultServer/server.xml src/main/liberty/config/server.xml
----
+
3. Add application arguments to your Spring Boot application configuration in the Liberty `server.xml` file
3. Add application arguments to your Spring Boot application configuration in the Liberty `server.xml` file.
+
[source,xml]
----
Expand All @@ -122,7 +122,7 @@ cp target/liberty/wlp/usr/servers/defaultServer/server.xml src/main/liberty/conf
</springBootApplication>
----
+
4. Add `println` to echo arguments in the output (use the `vi` command here, or your preferred editor) :
4. Add `println` to echo arguments in the output (use the `vi` command here, or your preferred editor).
+
[source,sh]
----
Expand Down Expand Up @@ -219,7 +219,7 @@ RUN configure.sh
+
(Note you can use the `full-java17-openj9-ubi` tag to build the equivalent Java 17 image.)
+
2. Build then run the image
2. Build then run the image.
+
[source,sh]
----
Expand All @@ -229,8 +229,8 @@ docker run -p 9080:9080 -p 9443:9443 -it springboot:demo

== Results

To recap, you can deploy a Spring Boot WAR to Liberty like any other WAR, or you can deploy it with an optimized deployment using special `liberty-maven-plugin` configuration and the `springBoot-3.0` feature configured in server.xml.
Though much of the programming model is the same across the two cases, there are some differences including the bootstrap mechanism.
To recap, you can deploy a Spring Boot WAR to Liberty like any other WAR, or you can configure an optimized deployment using special `liberty-maven-plugin` configuration and the `springBoot-3.0` feature in the `server.xml` file.
Though much of the programming model is the same across the two cases, there are some differences, including the bootstrap mechanism and the ability to create more efficient Docker layers with the optimized deployment.

== References
* Clone the link:https://github.com/scottkurz/spring-liberty[repository](https://github.com/scottkurz/spring-liberty) with the finished code for the sample app in this blog.
Expand Down

0 comments on commit 642559f

Please sign in to comment.