Groovy CRUD Web App Using Micronaut

Reading Time: 3 minutes

1. About

1.1 Introduction

Micronaut is an open-source JVM-based software framework for building lightweight, modular applications and microservices. It helps to create microservices with small memory footprints and quick startup time.

2. Use Case

Let’s take a use case. We are going to create a web app with the help of Groovy and Micronaut to perform CRUD operations. For that, we have to implement the CRUD web app so that it will have all the entries of flight records. We can Add, Update, Delete and Read all the records.

3. Pre-Requisite

You need to make sure that the following components are already installed in the system:

  1. JDK 1.8 or greater installed with JAVA_HOME.
  2. Groovy runtime.
  3. Micronaut.
  4. Gradle 3.6.1

4. Development

To create a Micronaut project just navigate to and create your starter project.


The project structure will be as follows-


Open the build.gradle file and add the following dependencies :

// HANA DB driver. 

// To access the VCAP variable of the app. This will be needed to read the public key using which the JWT token will be verified.

// To verify the JWT token using the public key certificate extracted using the above dependency. 

// To extract the user details and the roles from the JWT token. 

Create a FlightEntity class and annotate with @MappedEntity(‘SFLIGHT’)

Add entity feilds flightId, flightName, flightFrom, flightTo and flightDate where flightId field will be unique.
Annotate flightId with @Id and @Column(name = 'ID') and rest of field will be annotated with @Column

Create FlightRepository Repo class

Create FlightRepository Repo class and extends CrudRepository

Create FlightController class

//Add sFlightRepository bean of FlightRepository class
//Add controller method which will take FlightRepository object as a  parameter
    FlightController(FlightRepository sFlightRepository) {
        this.sFlightRepository = sFlightRepository

        //Add some records in the table, if the table empty.
        if (this.sFlightRepository.findAll().isEmpty()) {
   FlightEntity(flightId: 1,
                    flightName: 'IndiGo',
                    flightFrom: 'Mumbai',
                    flightTo: 'Chennai',
                    flightDate: new Date()))
   FlightEntity(flightId: 2,
                    flightFrom: 'New Delhi',
                    flightName: 'Air India',
                    flightTo: 'Mumbai',
                    flightDate: new Date()))
   FlightEntity(flightId: 3,
                    flightName: 'TruJet',
                    flightFrom: 'Agra',
                    flightTo: 'Delhi',
                    flightDate: new Date()))
   FlightEntity(flightId: 4,
                    flightName: 'SpiceJet',
                    flightFrom: 'Delhi',
                    flightTo: 'Pune',
                    flightDate: new Date()))

// Fetch all records
Add getAll(@Nullable Principal principal)
// Update particulat record of table
Add update(@Body FlightEntity sFlightEntity, @PathVariable('id') String id)

// Delete particulat record of table 
delete(@Body FlightEntity sFlightEntity, @PathVariable('id') String id)
// This is for admin, he can perform the operations.
operation(@Nullable @PathVariable('name') String name)

Create Main Application class

6. Work Flow

Run class


You can navigate to http://localhost:8080 , You can see the FLIGHT table is generated and is also having entries.


To add a record in a table just click on Create button


To update a record in a table just click on the update action button


To delete a record in a table just click on the delete action button


We have performed all the CRUD operations.

6. Conclusion

In this blog, we have covered the Groovy CRUD web app with the help of the Micronaut framework. Now you are ready with the understanding of the Groovy CRUD web app with the help of the Micronaut framework. For more, you can refer to the documentation:

7. References

Written by 

Gaurav Dubey is a Java Developer at Knoldus Software LLP. He has done M.CA from Kurukshetra University and completed Bachelor's Degree in Computer Science from M. D. University. He is a tech enthusiast with good knowledge of Java. He is majorly focused in Java practice. On the personal front, he loves to cook and travel.