5 way to go to production with Spring Boot
Spring Boot is pretty cool, what with things like autoconfiguration, property file management, and all. But did you know it’s ALSO really wicked at the different ways it simplifies taking your application to production?
1 — Deploying with Uber JARs

We’ve all created JAR files. In fact, most of the libraries we pick up and use, be it Spring libraries, Apache Commons, whatever, are JAR files.
But Java is really quirky in the sense that its one of those unique platforms where deployment…isn’t baked right in. Instead, you have to reach for something to host it.
That is, if you aren’t using Spring Boot.
Spring Boot brings us something called Uber JARs. It’s a JAR file that includes not just your application code, but also ALL the 3rd party dependencies your app needs to operate.
When you craft your Spring Boot application using start.spring.io, it will come loaded with the Spring Boot Maven Plugin (or Spring Boot Gradle plugin) which empowers your application during the build lifecycle to not only package up a standard JAR file with your code, but will also add those extra dependencies.
Since Java itself has never DIRECTLY supported JARs within JARs, the Spring Boot team has crafted a little glue code to handle this job for your. With all that applied, all it takes to run your app is:
$ java -jar myapp.jar
It’s something that’s always been in Spring Boot, and something that will always be there. And as Oliver Drotbohm once said, all you need on your target machine is a JVM!
2 — Docker containers

Something that has risen up FAST is the usage of Docker. Today, you can find just about anything you want, including Oracle databases, wrapped inside Docker containers.
So it’s natural that people want to bundle up their applications in Docker containers. In the past, this has always been tricky, because there is a certain nuance to “doing it right”.
Assembling a Docker container can involve a lot of wasted cycles if you mix your continuously changing code together with 3rd party dependencies that don’t.
It used to be that to put things together, you had to scour the wastelands of Google to find the right way to bundle your application along with JDK inside a container.
So the Spring Boot team set out to pull together all the right metadata and simplify the process. And now, with that application crafted a la start.spring.io, this is all it takes:
$ ./mvnw spring-boot:build-image
(Or gradlew bootBuildImage)
With this command, Spring Boot will assemble your Uber JAR and then bake a Docker container, ready to be run, pushed to the cloud, or published to Docker Hub.
3 — Native apps on GraalVM

What if startup time is VITAL for your application? Maybe you are running 10,000 copies and all that traditional Java startup time x 10,000 copies = a HUGE cloud bill? Or you are using Amazon’s Serverless Computing platform where spin-up time really NEEDS to be sub-second?
Say no more. GraalVM, the alternative to the JVM, can run Java apps in sub-second time by leveraging something known as AOT of Ahead of Time Compilation.
The Spring team has worked hand-in-hand with the GraalVM team to simplify and ease adoption of native applications. It principally involves folding in the right bits to the Spring portfolio making Spring Boot applications native-ready.
And the Spring team has coordinated with the GraalVM team to make tweaks and adjustments to enhance GraalVM itself.
For Spring Boot 2.x applications, all you need to do is add Spring Native when setting things up on start.spring.io, and all the right “extra settings” will be picked up in your application. As for Spring Boot 3 apps, native is, well, native! There will be no need. Stay tuned!
And if you’re wondering HOW to assemble a fully-loaded native Spring Boot application, you just do this:
$ ./mvnw spring-boot:build-image
Yes, the same command used to assemble a Docker container, when you have Spring Native applied, is used here as well. The difference is that Spring Boot’s build plugin will invoke Paketo Buildpacks to roll your a Docker container that has your code compiled via AOT mixed in with a GraalVM-based container.
4 — Creating Web Archive Files
Web Archive Files or WAR files are something that’s been around a long time. Everyone knows what they are.
And if you need a WAR file, all you must do on start.spring.io is click the tiny “War” radio button on the screen, right next to “Jar”. You’ll be setup just right!
WAR files are classic, work nicely on giant, lumbering application servers. Sluggish, slow to upgrade app servers.
Come to think of it, maybe we SHOULDN’T be assembling WAR files. This is 2022 and people are running thin, light servlet containers and Docker containers. They’re even using GraalVM, not giant app servers!
Forget I ever mentioned WAR files. What was I thinking?

5 — Executable JAR files
One key feature we sometimes need are applications that start when the server starts and stop when the server starts. Linux and BSD users will be somewhat familiar with “init 5” and “init 0”-type scripts used by the OS.
It shouldn’t surprise you that Spring Boot has a flag setting that lets you turn your JAR file into an executable that will obey the same runlevel settings.
You can truly make your JAR file executable by applying this tweak:
<project>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
</plugins>
</build>
</project>(Just check here for the Gradle equivalent!)
A key thing to point out, is that executable JAR files aren’t supported on all cloud platforms. There is a risk that it simply won’t run, so choose wisely.
And that, my friend, is five ways to take your Spring Boot app to production.
If you dig Spring Boot, then please stay tuned for my next article. But if you simply can’t wait, then check out the video below where you can learn three design patterns that DIED a just and deserved death in 2022!
— Greg
If you enjoy this writing, consider joining Medium for less than the price of a monthly latte.
Do you want to get a free tech e-book, be alerted to my discounts, and get even MORE content about SPRING BOOT? Then SIGN UP FOR MY NEWSLETTER.





