春のブートGradleのビルドプロジェクト

春のブートGradleのビルドプロジェクト


Gradleのは、IDEAプロジェクトを使用して作成しました

    ファイル - >新規作成 - >プロジェクト - >のGradle(左の列にあるオプション):操作が実質的に

    次のように定期的に生成されたプロジェクトディレクトリを作成した後:

  • 築きます
  • Gradleの
    • ラッパー
      • Gradleでは、wrapper.jar
      • gradle-wrapper.properties
  • SRC
    • ジャワ
    • リソース
  • テスト
    • ジャワ
    • リソース
  • build.gradle
  • gradlew
  • gradlew.bat
  • settings.gradle

春のブート設定

    2つのファイルを編集するには、以下の必要性:

    次のようにファイルのBuild.gradle内容が改変され、中央にはたartifactId、一般的に3番目のバージョンであり、一般のGroupID正面に依存しています。アリのクラウドストレージを使用するように構成されたリポジトリでは、遅すぎるダウンロードしないよう。

plugins {
    id 'java'
    id 'com.gradle.build-scan' version '2.0.2'
    id 'org.springframework.boot' version '2.0.5.RELEASE'
    id 'io.spring.dependency-management' version '1.0.7.RELEASE'
}

group 'seckill'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'

    implementation 'org.springframework.boot:spring-boot-dependencies:2.0.5.RELEASE'
    implementation 'org.springframework.boot:spring-boot-starter-web'

    testImplementation 'org.springframework.boot:spring-boot-starter-test'

    components {
        withModule('org.springframework:spring-beans') {
            allVariants {
                withDependencyConstraints {
                    // Need to patch constraints because snakeyaml is an optional dependency
                    it.findAll { it.name == 'snakeyaml' }.each { it.version { strictly '1.19' } }
                }
            }
        }
    }
}

buildScan {

    // always accept the terms of service
    termsOfServiceUrl = 'https://gradle.com/terms-of-service'
    termsOfServiceAgree = 'yes'

    // always publish a build scan
    publishAlways()
}

    :ファイルsetting.gradleの内容は、次のように改正された後、

rootProject.name = 'seckill'
enableFeaturePreview('IMPROVED_POM_SUPPORT')

ライティングのクラス

    まずソースcom.seckill.spring(等価COM / seckill /春)の下で生成された、のsrc / javaディレクトリ

    次のように読み込むプログラムエントリのsrc / JavaのApplication.java、中クラスの作成:

package com.seckill.spring;

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

    ルートルーティングで定義され、以下のようなコードのHello Worldを返しているのHelloWorld、ディレクトリ・コントローラ、およびコントローラのディレクトリ作成したクラスをcom.seckill.spring / SRC / javaの下に作成:

package com.seckill.spring.controllers;

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

import java.util.HashMap;
import java.util.Map;

@RestController
public class HelloWorld {
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public Map helloWorld() {
        Map<String, Object> ret = new HashMap<>();
        ret.put("ret", "Hello World");
        return ret;
    }
}

アクセスを実行します

  • Applicationクラスを実行して、あなたは8080でコンソールのデフォルトのリスニングポートから見ることができます
  • ブラウザアクセス:localhostを:8080、あなたは、返される文字列のHello Worldを見ることができます

参考リンク

おすすめ

転載: www.cnblogs.com/freedom-only/p/11285351.html
おすすめ