通過gradle創(chuàng)建spring boot項目

1.首先,通過命令行創(chuàng)建一個目錄,進(jìn)行初始化,如圖1所示:

圖1 初始化

我們用idea打開初始化的項目,如圖2所示:
圖2 通過IDEA打開初始化后的項目

2.修改build.gradle文件.在Spring boot官網(wǎng)中右側(cè)Building an Application with Spring Boot中例子build.gradle文件中的內(nèi)容復(fù)制到本地build.gradle文件中.

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.3.RELEASE")
    }
}
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'

jar {
    baseName = 'gs-spring-boot'
    version =  '0.1.0'
}

repositories {
    mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8
![Uploading Screenshot from 2017-05-06 00-41-42_078590.png . . .]


dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    // tag::actuator[]
    compile("org.springframework.boot:spring-boot-starter-actuator")
    // end::actuator[]
    // tag::tests[]
    testCompile("org.springframework.boot:spring-boot-starter-test")
    // end::tests[]
}

3.由于spring boot 由其特定的目錄結(jié)構(gòu),通過命令行創(chuàng)建目錄結(jié)構(gòu),如圖3所示.


圖3 通過命令行創(chuàng)建目錄結(jié)構(gòu)

在IDEA中將main下的java文件夾,設(shè)置為Sources Root,將test文件夾下的java文件夾設(shè)置為resources設(shè)置為Test sources Root,將resources設(shè)置為Resources Root.
設(shè)置后的界面如圖4所示.


圖4 添加目錄結(jié)構(gòu)

4.在main對應(yīng)的java下創(chuàng)建一個包并添加一個類

5.運行程序
使用`gradle bootRun`啟動程序,可以看到tomcat已經(jīng)在8080端口啟動.

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

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

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