[JAVA] Hello World with Spring Boot

environment

Creating a project

First, create a project. Click ** Create New Project **. スクリーンショット 2019-06-07 21.51.15.png

Select ** Gradle ** and ** JDK ** and press ** Next **. スクリーンショット 2019-06-07 22.01.05.png

Enter the ** Group ID ** and ** Artifact ID ** and press ** Next **. ・ Group ID: HelloWorld -Artif ID: HelloWorld スクリーンショット 2019-06-07 22.16.43.png

When saving, check ** Use automatic import ** and press ** Next ** so that Gradle will automatically resolve the dependency. スクリーンショット 2019-06-07 22.16.51.png

Enter the ** project name ** and press ** Done **. ・ Project name: Hello World

If the following pop-up appears, press ** Allow **. スクリーンショット 2019-06-07 22.17.25.png

Creating an application

Now, let's write a program that actually displays Hello World on the browser using Spring Boot.

Right-click (project Root) / src / main / java and create a new class. Specify the class in the name, including the package name separated by. (Dot). ** Name: ** jp.example.Application

Since an error occurs when importing, the dependency is resolved. スクリーンショット 2019-06-08 15.34.59.png

build.gradle


plugins {
    id 'java'
}

group 'HelloWorld'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.1.3.RELEASE'
}

I will write the product code.

Application.java


package jp.co.example;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

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

HelloController


package jp.co.example;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {
    @RequestMapping("/")
    public static String Hello(){
        return "Hello World!";
    }
}

Execute and access the following address. http://localhost:8080/

It is OK if the returned character string is output on the browser.

Recommended Posts

Hello World with Spring Boot
Hello World with Spring Boot!
Hello World with Spring Boot
Until "Hello World" with Spring Boot
(Intellij) Hello World with Spring Boot
Hello World with Eclipse + Spring Boot + Maven
(IntelliJ + gradle) Hello World with Spring Boot
Hello world! With Spring Boot (Marven + text editor)
[Java] Hello World with Java 14 x Spring Boot 2.3 x JUnit 5 ~
Spring Boot Hello World in Eclipse
Hello World (REST API) with Apache Camel + Spring Boot 2
Hello World (console app) with Apache Camel + Spring Boot 2
[Practice! ] Display Hello World in Spring Boot
How Spring Security works with Hello World
Hello World with Micronaut
Download with Spring Boot
Compare Hello, world! In Spring Boot with Java, Kotlin and Groovy
Hello World at explosive speed with Spring Initializr! !! !!
Try to display hello world with spring + gradle
Generate barcode with Spring Boot
Implement GraphQL with Spring Boot
Get started with Spring boot
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
Getting Started with Spring Boot
Create microservices with Spring Boot
Send email with spring boot
Hello World with SpringBoot / Gradle
Hello, World! With Asakusa Framework!
Spring Boot2 Web application development with Visual Studio Code Hello World creation
Hello World comparison between Spark Framework and Spring Boot
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
Hello World with Docker and C
Get validation results with Spring Boot
Create an app with Spring Boot
Google Cloud Platform with Spring Boot 2.0.0
Check date correlation with Spring Boot
Hello World with GlassFish 5.1 + Servlet + JSP
Create PDF with itext7 ~ Hello World ~
I tried GraphQL with Spring Boot
[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
Hello World with GWT 2.8.2 and Maven
Message cooperation started with Spring Boot
Spring Boot gradle build with Docker