1.首先,通過命令行創建一個目錄,進行初始化,如圖1所示:
圖1 初始化
我們用idea打開初始化的項目,如圖2所示:
圖2 通過IDEA打開初始化后的項目
2.修改build.gradle文件.在Spring boot官網中右側Building an Application with Spring Boot中例子build.gradle文件中的內容復制到本地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 由其特定的目錄結構,通過命令行創建目錄結構,如圖3所示.
圖3 通過命令行創建目錄結構
在IDEA中將main下的java文件夾,設置為Sources Root,將test文件夾下的java文件夾設置為resources設置為Test sources Root,將resources設置為Resources Root.
設置后的界面如圖4所示.
圖4 添加目錄結構
4.在main對應的java下創建一個包并添加一個類
5.運行程序
使用`gradle bootRun`啟動程序,可以看到tomcat已經在8080端口啟動.