Compare Hello, world! In Spring Boot with Java, Kotlin and Groovy

I compared Hello, world! With Spring Boot with Java, Kotlin and Groovy, so make a note.

This article is based on the macOS environment.

Install Spring Boot CLI

Install Spring Boot CLI with Homebrew.

$ brew tap pivotal/tap
$ brew install springboot

If you execute the following command in the terminal, the version will be displayed. Note that if the Rails environment is local, the spring used by Rails may be executed, so adjust the PATH environment variable.

$ spring --version
Spring CLI v1.5.4.RELEASE

Create a Hello project

Create a Hello project with the following command. Use Gradle as the build tool, add the web as a dependency, use Java as the language, and extract it to the hello directory as a project named Hello.

$ spring init --build=gradle -d=web -l=java -n=hello hello

Code is generated in Kotlin and Groovy by changing -l = java to -l = kotlin or -l = groovy.

You can edit the project code with a suitable text editor, but if you want to edit it with IntelliJ IDEA Ultimate or IntelliJ IDEA Community, open the project directory with the following command.

$ idea hello

Implement Hello, world!

Try implementing Hello, world! In Java, Kotlin and Groovy.

src/main/java/com/example/hello/HelloApplication.java


package com.example.hello;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class HelloApplication {

	public static void main(String[] args) {
		SpringApplication.run(HelloApplication.class, args);
	}

	@RequestMapping("/")
	String hello() {
		return "Hello, world!";
	}
}

src/main/kotlin/com/example/hello/HelloApplication.kt


package com.example.hello

import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@SpringBootApplication
@RestController
class HelloApplication {
    @RequestMapping("/")
    fun hello() = "Hello, world!"
}

fun main(args: Array<String>) {
    SpringApplication.run(HelloApplication::class.java, *args)
}

src/main/groovy/com/example/hello/HelloApplication.groovy


package com.example.hello

import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@SpringBootApplication
@RestController
class HelloApplication {

	static main(args) {
		SpringApplication.run HelloApplication, args
	}

	@RequestMapping("/")
	def hello() {
		"Hello, world!"
	}
}

There is not much difference with this kind of code.

Run the Hello project

Go to the Hello! Project directory and run the bootRun task in Gradle to start the web server.

$ ./gradlew bootRun

Send a GET request

When I send a GET request to the launched Hello project, Hello, world! Is returned.

$ curl localhost:8080
Hello, world!

This time I tried Hello, world! With Spring Boot and Java / Kotlin / Groovy. I thought that Spring Boot would be a good micro framework at the beginning, but I tried it, but the result was that it lacked the feeling of micro because of the import statement. I think Spring Boot is a good environment where you can start from a microscopic place and evolve into a full stack, so I hope there will be more information that you can play with Spring without knowing anything.

References

https://docs.spring.io/spring-boot/docs/current/reference/html/

Recommended Posts

Compare Hello, world! In Spring Boot with Java, Kotlin and Groovy
[Java] Hello World with Java 14 x Spring Boot 2.3 x JUnit 5 ~
Hello World with Spring Boot
Hello World with Spring Boot!
Hello World with Spring Boot
Spring Boot Hello World in Eclipse
Until "Hello World" with Spring Boot
Hello world with Kotlin and JavaFX
(Intellij) Hello World with Spring Boot
Hello world in Java and Gradle
Hello World with Eclipse + Spring Boot + Maven
[Practice! ] Display Hello World in Spring Boot
"Hello, World!" With Kotlin + CLI in 5 minutes
Hello world with Kotlin and Tornado FX
(IntelliJ + gradle) Hello World with Spring Boot
"Hello World" in Java
Hello World in Java
Hello world! With Spring Boot (Marven + text editor)
Hello World (REST API) with Apache Camel + Spring Boot 2
Hello World comparison between Spark Framework and Spring Boot
Hello World (console app) with Apache Camel + Spring Boot 2
Let's create a TODO application in Java 2 I want to create a template with Spring Initializr and make a Hello world
[Java / Kotlin] Escape (sanitize) HTML5 support with unbescape [Spring Boot]
How to call and use API in Java (Spring Boot)
Domain Driven Development with Java and Spring Boot ~ Layers and Modules ~
Hello World with Docker and C
[Java] LINE integration with Spring Boot
Hello World with GWT 2.8.2 and Maven
Easily develop web applications with STS and Spring Boot. In 10 minutes.
Hello world with Java template engine Thymeleaf
HTTPS with Spring Boot and Let's Encrypt
Create Java Spring Boot project in IntelliJ
Java development with Codenvy: Hello World! Run
How Spring Security works with Hello World
Minimal Java environment construction and Hello World
A story about a Spring Boot project written in Java that supports Kotlin
Spring Boot2 Web application development with Visual Studio Code Hello World creation
Java, Hello, world!
Java Hello World
Test controller with Mock MVC in Spring Boot
Asynchronous processing with regular execution in Spring Boot
Hello World with JavaFX 11 (OpenJFX) in Liberica JDK 11
Output request and response log in Spring Boot
Hello World at explosive speed with Spring Initializr! !! !!
Build Java environment and output hello world [Beginner]
Java tips-Create a Spring Boot project in Gradle
Display "Hello World" in the browser using Java
Display "Hello World" in the browser using Java
[JAVA] [Spring] [MyBatis] Use IN () with SQL Builder
[Java] Article to add validation with Spring Boot 2.3.1.
Try to display hello world with spring + gradle
Encrypt / decrypt with AES256 in PHP and Java
Hello World with Java Servlet and JSP (Easy web server startup with Maven + Jetty)
Hello World, a cross-platform GUI app with Groovy running on the Java platform
Create a portfolio app using Java and Spring Boot
Include external jar in package with Spring boot2 + Maven3
Try using DI container with Laravel and Spring Boot
[Java] [Spring Boot] Specify runtime profile --Spring Boot starting with NetBeans
Summary of ToString behavior with Java and Groovy annotations
Spring Security usage memo: Cooperation with Spring MVC and Boot
Java Learning (1)-Hello World