Eclipse中的STS插件
- 打开Eclipse-Help-Eclipse Marketplace-popular
![Eclipse STS](https://img-blog.csdn.net/20170725152114672?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvR3VvaGVuZ2hlbmdoYWhh/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
- 下载完成后,重启eclipse,选择新建project-spring-spring start project,新建Spring boot 项目。
![start project](https://img-blog.csdn.net/20170725152331946?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvR3VvaGVuZ2hlbmdoYWhh/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
项目快速解析
- 新建的项目目录大概如下
![boot目录结构](https://img-blog.csdn.net/20170725153035411?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvR3VvaGVuZ2hlbmdoYWhh/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
- 整体目录结构和Spring项目一样,只不过Spring boot的配置文件迁移到了application.yml(或者application.propertis)。项目的入口为BootTestApplication.java的main函数入口。
- 在maven配置的pom.xml里面相较于之前的项目添加了以下依赖:
![pompro](https://img-blog.csdn.net/20170725153356662?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvR3VvaGVuZ2hlbmdoYWhh/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
- BootTestApplication中@SpringBootApplication取代了Spring项目中的@Configuration、@EnableAutoConfiguration、@ComponentScan。因此,我们所有的bean需要在BootTestApplication的同级目录下被扫描。
![BootTestApplication](https://img-blog.csdn.net/20170725153510261?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvR3VvaGVuZ2hlbmdoYWhh/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
快速开发项目
<dependency><groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
- 在com.example.demo下新建controller包,新建controller包,在下面建立Hello Controller.java。
@RestController
public class HelloController {
@RequestMapping(value="/hello", method=RequestMethod.GET)
public String HelloController() {
return "Hello World!";
}
}
- 右键BootTestApplication.java-run as java application,运行项目。
- 在浏览器输入localhost:8080/hello。
![hello](https://img-blog.csdn.net/20170725155350804?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvR3VvaGVuZ2hlbmdoYWhh/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
修改访问端口和默认路径
- 在这里我们使用更加好看的application.yml方式配置。只需要将默认的application.properties替换为application.yml即可。
- 在yml添加以下代码,修改端口为8081,后缀添加路径为/guo
server:
port: 8081
context-path: /guo