[JAVA] (IntelliJ + gradle) Hello World with Spring Boot

Introduction

I want to develop Spring Boot with IntelliJ. Since the development project I am currently involved in is this combination, I built it to study the mechanism. I want to make a REST API that works with mysql.

--Environmental information - Windows10 - IntelliJ IDEA Community Edition 2019.1.1 - Spring Boot 2.1.5

Project creation

Create a project template with Spring Initializr linked below. https://start.spring.io/

image.png

--Project: Select [Gradle Project] --Language: As it is --Spring Boot: As it is --Project Metadata: As is --Dependencies: Added [Spring Web Starter]

After setting

image.png

After completing the settings, click the "Generate the project" button at the bottom of the screen. The project zip will be downloaded, so unzip it.

Project import

  1. Select "build.gradle" from the unzipped folder in Explorer and right-click. Open from program → select IntelliJ
  2. The IntelliJ dialog will be displayed, so click OK without changing anything. (Maybe you need to choose jdk) paste.png
  3. Wait for the build to finish.
  4. When finished, it should have the following configuration. paste2.png

Edit to display Hello World

  1. Edit DemoApplication.java as follows.

DemoApplication.java


package com.example.demo;

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 DemoApplication {

	@RequestMapping("/")
	String index(){
		return "Hello World!";
	}

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

}

to start

From the Gradle window, execute Tasks → application → bootRun.

Post-execution console paste3.png

Check with browser

Connect to http: // localhost: 8080 /. Hello World is output!

image.png

Recommended Posts

(IntelliJ + gradle) Hello World with Spring Boot
(Intellij) Hello World with Spring Boot
Hello World with Spring Boot
Hello World with Spring Boot!
Hello World with Spring Boot
Hello World with Eclipse + Spring Boot + Maven
Hello world! With Spring Boot (Marven + text editor)
[Java] Hello World with Java 14 x Spring Boot 2.3 x JUnit 5 ~
Try to display hello world with spring + gradle
Hello World with SpringBoot / Gradle
Hello World (REST API) with Apache Camel + Spring Boot 2
Hello World (console app) with Apache Camel + Spring Boot 2
Spring Boot Hello World in Eclipse
Spring Boot gradle build with Docker
[Practice! ] Display Hello World in Spring Boot
How Spring Security works with Hello World
Compare Hello, world! In Spring Boot with Java, Kotlin and Groovy
Download with Spring Boot
Create a website with Spring Boot + Gradle (jdk1.8.x)
Run Scala applications with Spring Boot through Gradle
Build Spring Boot project by environment with Gradle
Show a simple Hello World with SpringBoot + IntelliJ
I wanted to gradle spring boot with multi-project
Spring Boot2 Web application development with Visual Studio Code Hello World creation
Generate barcode with Spring Boot
Implement GraphQL with Spring Boot
Spring Boot 2 multi-project in Gradle
Run LIFF with Spring Boot
SNS login with Spring Boot
Hello World with VS Code!
File upload with Spring Boot
Spring Boot starting with copy
Spring Boot starting with Docker
Set cookies with Spring Boot
Use Spring JDBC with Spring Boot
Add module with Spring Boot
Create microservices with Spring Boot
Hello World comparison between Spark Framework and Spring Boot
Hello, World! With Asakusa Framework!
Create a Hello World web app with Spring framework + Jetty
Use Basic Authentication with Spring Boot
gRPC on Spring Boot with grpc-spring-boot-starter
Create an app with Spring Boot 2
Hot deploy with Spring Boot development
Database linkage with doma2 (Spring boot)
Spring Boot programming with VS Code
Inquiry application creation with Spring Boot
Hello world with Kotlin and JavaFX
Get validation results with Spring Boot
Create an app with Spring Boot
Google Cloud Platform with Spring Boot 2.0.0
Implement Spring Boot application in Gradle
Create PDF with itext7 ~ Hello World ~
[Java] LINE integration with Spring Boot
Beginning with Spring Boot 0. Use Spring CLI
"Hello world" for ImageJ with Eclipse
I tried Flyway with Spring Boot
Develop Processing with IntelliJ + Kotlin + Gradle
Hello world in Java and Gradle
Message cooperation started with Spring Boot
Until you run Hello World of JavaFX with VS Code + Gradle