See below.
build.gradle I will describe the definition in build.gradle referring to here.
build.gradle
plugins {
id 'org.springframework.boot' version '2.3.3.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
def defaultEncoding = 'UTF-8'
tasks.withType(AbstractCompile) each { it.options.encoding = defaultEncoding }
compileTestJava {
options.encoding = defaultEncoding
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}
Reimport in the right pane Gradle.
Hello World Listed in two classes.
BootApp.java
package org.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class BootApp {
public static void main(String[] args) {
SpringApplication.run(BootApp.class, args);
}
}
Controller.java
package org.example;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
@RestController
public class Controller {
@RequestMapping("/")
public String index() {
return "\nHello World!";
}
}
Run BootApp.java and check with GitBash.
$ curl http://localhost:8080/
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 13 100 13 0 0 149 0 --:--:-- --:--:-- --:--:-- 149
Hello World!
Unify character code to utf8 with gradle
Recommended Posts