Springboot--工程搭建

搭建Springboot工程

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

start

  1. 選擇構建工具:Maven或者Gradle。我選了Gradle,這也是我第一次用gradle。
  2. 選擇SpringBoot版本
  3. Dependencies中搜索自己想依賴的包,比如ElasticSearch
  4. 生成是單module項目。
  5. 下載後導入工程,可以開始幹活了。
  6. 下圖爲新增module後的截圖

導入項目

  1. 新增module後會自動新增一個setting.gradle文件,沒有則手動新建一個。
  2. 修改gradle版本: gradle-wrapper.properties(gradle安裝和maven一樣)
  3. 修改repositories 地址 * init.gradle*,默認爲maven.oschina.net(貌似不能用了)改爲maven.aliyun.com;
  4. 修改gradle內容:依賴以及設置 build.gradle
  5. build項目;
  6. 完成項目搭建

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內容

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

項目 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'
    }
}

代碼

代碼請移步 Github參考地址

如有疑問請加公衆號(K171),如果覺得對您有幫助請 github start
公衆號_k171

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章