SpringBoot--工程搭建

搭建Springboot工程

可以選擇自己手動(dòng)搭建,也可以選擇start.spring.io快速搭建。
偷懶直接用,生成工程。

start
  1. 選擇構(gòu)建工具:Maven或者Gradle。我選了Gradle,這也是我第一次用gradle。
  2. 選擇SpringBoot版本
  3. Dependencies中搜索自己想依賴的包,比如ElasticSearch
  4. 生成是單module項(xiàng)目。
  5. 下載后導(dǎo)入工程,可以開始干活了。
  6. 下圖為新增module后的截圖
導(dǎo)入項(xiàng)目
  1. 新增module后會(huì)自動(dòng)新增一個(gè)setting.gradle文件,沒有則手動(dòng)新建一個(gè)。
  2. 修改gradle版本: gradle-wrapper.properties(gradle安裝和maven一樣)
  3. 修改repositories 地址 ** init.gradle**,默認(rèn)為maven.oschina.net(貌似不能用了)改為maven.aliyun.com;
  4. 修改gradle內(nèi)容:依賴以及設(shè)置 build.gradle
  5. build項(xiàng)目;
  6. 完成項(xiàng)目搭建

gradle-wrapper.properties

修改gradle版本
#Tue Jan 10 11:28:22 CST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

init.gradle: C:\Users\xxxxx.gradle

allprojects{
    repositories {
        def REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public'
        all { ArtifactRepository repo ->
            if(repo instanceof MavenArtifactRepository){
                def url = repo.url.toString()
                if (url.startsWith('https://repo1.maven.org/maven2') || url.startsWith('https://jcenter.bintray.com/')) {
                    project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
                    remove repo
                }
            }
        }
        maven {
            url REPOSITORY_URL
        }
    }
}

setting.gradle內(nèi)容

rootProject.name = 'bootcwenao'
include 'common-bootcwenao'
include 'apigateway-bootcwenao'
include 'discovery-bootcwenao'
include 'configserver-bootcwenao'

項(xiàng)目 build.gradle

buildscript {
    ext {
        springBootVersion = '1.4.3.RELEASE'
    }
    repositories {
        mavenCentral()

        maven { url "http://maven.aliyun.com/nexus/content/repositories/snapshots"}
    }

    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

allprojects {
    apply plugin: 'idea'
    group = 'com.bootcwenao'
    version = '1.0-SNAPSHOT'
}

subprojects {
    ext {
        springCloudVersion = 'Camden.SR3' //'Brixton.RELEASE'
        mybatisSpringBootVersion='1.2.0'
        mybatisVersion = '3.2.8'
        mysqlVersion = '5.1.38'
        okhttpVersion = '3.4.1'
        druidVersion = '1.0.18'
        commonsLang3Version = '3.4'
        snappyVersion = '1.1.2.1'


    }

    apply plugin: 'java'


    sourceCompatibility = 1.8
    targetCompatibility = 1.8

    repositories {
        mavenLocal()

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

    sourceSets {
        main {
            java.srcDir('src/main/java')
            resources.srcDir('src/main/resources')
        }
        test {
            java.srcDir('src/test/java')
            resources.srcDir('src/test/resources')
        }
    }

    task wrapper(type: Wrapper) {
        gradleVersion = '3.3'
    }
}

代碼

代碼請(qǐng)移步 Github參考地址

如有疑問請(qǐng)加公眾號(hào)(K171),如果覺得對(duì)您有幫助請(qǐng) github start

公眾號(hào)_k171

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容