0
2

SpringBoot + Java + Gradle環境で"Hello World"

Posted at

環境

  • SpringBoot 2.2.7
  • Java 1.8
  • Gradle 6.3

Javaの設定(IntelliJ )

ファイル < プロジェクト構造 < プロジェクト設定
< プロジェクト
image.png
< モジュール
ソース
image.png
依存関係
image.png

ファイル < プロジェクト構造 < プラットフォーム設定
image.png

ファイル < 設定 < ビルド、実行、デプロイ < ビルドツール < Gradle
image.png

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);
    }

}

動作確認

ビルドして実行
image.png

http://localhost:8080/
image.png

補足

intellijでgradleをリフレッシュする方法
表示 < ツールウィンドウ < Gradle を表示して、左上のリロードっぽいボタンを押す
image.png

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2