Hello World with Spring Boot + Kotlin

Turkdogan Tasdelen
2 min readApr 9, 2021
Spring Boot

In this post, we will create a very simple hello world example by using the Spring Boot with Kotlin language. The key idea is to implement a rest controller to return the famous message: Hello World!

The first step to manage the project is to use a build management system such as Gradle or Maven. In this tutorial, we will use Gradle to compile and run the project.

Create an Empty Spring Boot Project

Writing all the required configurations is a time-consuming and error-prone task. Luckily, Spring Initializr is an online service to provide starter templates for Spring Boot projects. Let us open https://start.spring.io and select Gradle and Kotlin options. We will implement a RestController to handle the incoming requests. Therefore, we need to add Spring Web from the required libraries. Then, we can download the project by clicking the generate button.

Here is the final representation of the choices

Spring Initializr Page

There is nothing special about now but we can even run the project by the using following command from terminal (for MacOS and Linux environments).

For MacOS and Linux environments
./gradlew bootRun

For Windows the following one must be executed in the project repository:

gradlew bootRun
Starting Spring Boot with Gradle

Gradle will download required components by reading the required libraries from build.gradle in the project. Since we downloaded it from the spring.io page. If you check this file, you will see that it contains Spring Boot and Kotlin related libraries.

Lets Create The Rest Controller

Normally using an advanced development environment such as IntelliJ,
Eclipse or Visual Studio Code is a better choice to increase productivity. But for this specific hello world example, even a simpler editor is enough.

HelloWorldController returns Hello World for http://localhost:8080

This is the first introduction tutorial about the Spring Boot. There are many pre-configured options, and we have not examined the structure of the project yet. I plan to write about more advanced features of Spring Boot such as logging, scheduling, containerization, integration with other popular technologies such as MongoDB.

--

--