First, create a project. Click ** Create New Project **.
Select ** Gradle ** and ** JDK ** and press ** Next **.
Enter the ** Group ID ** and ** Artifact ID ** and press ** Next **. ・ Group ID: HelloWorld -Artif ID: HelloWorld
When saving, check ** Use automatic import ** and press ** Next ** so that Gradle will automatically resolve the dependency.
Enter the ** project name ** and press ** Done **. ・ Project name: Hello World
If the following pop-up appears, press ** Allow **.
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.
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