1.首先,通过命令行创建一个目录,进行初始化,如图1所示:

我们用idea打开初始化的项目,如图2所示:

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所示.

在IDEA中将main下的java文件夹,设置为Sources Root,将test文件夹下的java文件夹设置为resources设置为Test sources Root,将resources设置为Resources Root.
设置后的界面如图4所示.

4.在main对应的java下创建一个包并添加一个类

5.运行程序
使用`gradle bootRun`启动程序,可以看到tomcat已经在8080端口启动.
网友评论