Migrating from Spring Boot to Micronaut

Vindya Perera
2 min readDec 16, 2020

--

Spring Boot is an open source Java-based framework used to create micro Services. It is developed by Pivotal Team and is used to build stand-alone and production ready spring applications.

Micronaut is a JVM-based framework for building lightweight, modular applications. Developed by OCI, the same company that created Grails, It is the latest framework designed to make creating microservices quick and easy.

Today we will talk about migrating from Spring Boot to Micronaut. First of them, Spring Boot is currently the most popular and opinionated framework in the JVM world. On the other side of the barrier is staying Micronaut, quickly gaining popularity framework especially designed for building server less functions or low memory-footprint microservices. So most of the light weighted microservices are tend to be implemented using Micronaut nowadays.

Since Micronaut took quite a few principles from Spring Boot, migration is pretty easy. Roughly, the process looks something like this:

  1. Add Micronaut’s core Maven dependencies.
  2. Find out which Spring Boot Starters you use, and find the corresponding Micronaut Project.
  3. Fix compilation errors by replacing imports (Micronaut generally uses the same annotation names as Spring).
  4. Fix your application.yaml configuration file.
  5. Run it.

However, there are a few gotchas:

  • Spring’s default bean scope is Singleton while Micronaut’s default bean scope is Prototype. If you just remove @Component/@Service/@Repository/etc and let Micronaut do its magic, you might unintentionally end up with multiple instances of your bean. If that’s a problem, remember to mark your beans with @Singleton (javax.inject.Singleton) to mimic Spring’s behavior.
  • Spring Boot supports exposing the management interface on a different port (than your web application) for extra security. This is not supported by Micronaut.

--

--

Vindya Perera

Power is gained by sharing knowledge, not hoarding it.