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端口啟動.