One Framework a Day keeps the Boredom Away: Kotlin/Spring5/ReactiveMongoDB

Welcome to this new edition of One Framework a Day keeps the Boredom Away. In this series I will show you how to deploy a particular framework on Clever Cloud every day until I want to go back to boredom. Today it's about a bunch of interesting technologies: Kotlin, Spring 5 and MongoDB.

If you want to tag along, make sure you have git, a Clever Cloud account and that you have installed our CLI Clever-Tools.

What is Kotlin, Spring 5 and Reactive MongoDB?

This time we get to talk about all these things in one post because of a code sample I found. Someone on twitter asked us if Kotlin code could be deployed on Clever Cloud. The answer is yes. You can deploy anything that can be packaged as a Jar or War. So that means Kotlin, but also Ceylon, Clojure, Groovy, Scala and many more. So what is Kotlin?

Kotlin is a statically-typed programming language that runs on the Java virtual machine and also can be compiled to JavaScript source code or use the LLVM compiler infrastructure.

It's also worth noting that it can target native environment beyond the JVM. So it can be used to write iOS app for instance. This post on multiplatform native developement with Kotlin will give you a better idea of the many things you can do.

Anway I looked for a Kotlin sample online and I found the traditional Pet Clinic sample written in Kotlin with Spring 5 and Reactive MongoDB. Which is nice because Spring 5 is all about being reactive. And Kotlin is a great fit for that because of its Lambdas support. But we are not going to look at the code, we are going to look at how to deploy this Kotlin/MongoDB project on Clever Cloud.

Setup

Here are the steps you need to go through to deploy this application:

  • Clone the project: git clone https://github.com/ssouris/petclinic-spring5-reactive
  • Get in the project: cd petclinic-spring5-reactive
  • Create our PostgreMongoDB add-on: clever addon create mongodb-addon --plan peanut petClinicMongo
  • Create our application: clever create --type gradle petClinic
  • Link our MongoDb add-on: clever service link-addon petClinicMongo

Setup the necessary environment variables for configuration:

clever env set GRADLE_DEPLOY_GOAL bootRun
clever env set SPRING_DATA_MONGODB_URI `clever env | awk  -F = '/MONGODB_ADDON_URI/ { print $2}'`

Here we start by specifying which Gradle goal to run. This goal compiles and runs the application. Then we configured the MongoDB connection.

Deploy

To deploy your application, run clever deploy then clever open. You should see the logs of your application being ran successfuly then have the website open in your default web browser. And as you can see your Kotlin project is up and running and talking to a MongoDB database the reactive way.

Blog

À lire également

Clever Tools: a year of enhancements for your deployments, on the road to v4

A command line interface (CLI) is at the core of developer experience. At Clever Cloud, we have been providing Clever Tools for almost 10 years.
Engineering Features

Otoroshi with LLM: simplify your API and AI service management on Clever Cloud

Your applications and services are evolving in an increasingly complex environment, requiring effective management of APIs and interactions with artificial intelligence models such as the very popular LLMs (Large Language Models).
Features

Markitdown-as-a-Service: from AI to production on Clever Cloud

Every day, new tools are released, AI brings new perspectives, you have new ideas. It's one of Clever Cloud's missions to help you to develop and test them in real-life conditions, effortlessly, before making them available to everyone.
Engineering