一.什么是spring boot
Takes an opinionated view of buildingproduction-ready Spring applications. Spring Boot favors convention overconfiguration and is designed to get you up and running as quickly as possible.
摘自官网
翻译:采纳了建立生产就绪Spring应用程序的观点。 Spring Boot优先于配置的惯例,旨在让您尽快启动和运行。
springboot 致力于简洁,让开发者写更少的配置,程序能够更快的运行和启动。它是下一代javaweb框架,并且它是spring cloud(微服务)的基础。
二、搭建第一个sping boot 程序
可以在start.spring.io上建项目,也可以用idea构建。本案列采用idea.
具体步骤:
newprpject
->spring initializr
->{name :firstspringboot ,
type: mavenproject,packaging:jar ,
..}
->{spring version :
1.5.2web: web }
-> ....
应用创建成功后,会生成相应的目录和文件。
其中有一个Application类,它是程序的入口:
@SpringBootApplication
publicclass FirstspringbootApplication {
publicstaticvoidmain
(String[] args) {
SpringApplication.run(FirstspringbootApplication.class, args);
}
}
在resources文件下下又一个application.yml文件,它是程序的配置文件。默认为空,写点配置 ,程序的端口为8080,context-path为 /springboot:
server:
port
:
8080
context
-path: /springboot
写一个HelloController:
@RestController
//等同于同时加上了@Controller和@ResponseBody
publicclass HelloController {
//访问/hello或者/hi任何一个地址,都会返回一样的结果
@RequestMapping(
value= {
"/hello",
"/hi"},method = RequestMethod.GET)<