1、去这里下载https://start.spring.io/
a.选择Switch to the full version 进行各种配置
b.Packaging 为了以后方便最好还是选择 war
c.点击 Generate Project 下载
2、解压并用eclipse打开
我的长这个样子
a.找到自动生成的一个类xxxxApplication 譬如DemoApplication 启动程序直接以这个为主类像运行普通JAVA程序似的运行就可以
具体操作:右键类文件->Run As->Java Application
b.此时控制台输出一堆,不用管他
最后出现这个就证明启动成功了
2018-10-18 09:37:31.172 INFO 744 — [ main] com.mnn.DemoApplication : Started DemoApplication in 2.687 seconds (JVM running for 3.202)
c.浏览器访问http://127.0.0.1:8080/
出现这个就证明启动成功了
3、 编写第一个controller
PS:需要导入包
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
a. 新建一个类
譬如这样
package com.mnn;
public class HelloController {
}
然后添加注解把它标识为一个Controller
package com.mnn;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@RequestMapping("/hello")
public String h()
{
return "helloWorld";
}
}
然后重新运行程序访问http://127.0.0.1:8080/hello就可以看到
springBoot启动成功,剩下的自行摸索
PS:springBoot实现热加载即开发环境
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>