環境
- SpringBoot 2.2.7
- Java 1.8
- Gradle 6.3
Javaの設定(IntelliJ )
ファイル < プロジェクト構造 < プロジェクト設定
< プロジェクト
< モジュール
ソース
依存関係
ファイル < 設定 < ビルド、実行、デプロイ < ビルドツール < Gradle
build.gradle / gradle-wrapper.properties
※コピペでOK
build.gradle
plugins {
id 'org.springframework.boot' version '2.2.7.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
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()
}
gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
HelloWorldが表示されるように実装
HelloWorldApplication.java
package com.example.helloworld;
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;
@RestController
@SpringBootApplication
public class HelloWorldApplication {
@RequestMapping("/")
String Index() {
return "Hello World";
}
public static void main(String[] args) {
SpringApplication.run(HelloWorldApplication.class, args);
}
}
動作確認
補足
intellijでgradleをリフレッシュする方法
表示 < ツールウィンドウ < Gradle を表示して、左上のリロードっぽいボタンを押す