一、簡介
Springboot是Spring社區發佈的一個開源項目,用於快速構建Spring項目,習慣因爲配置的方式,極大簡化開發過程,減小傳統的開發中繁瑣的配置,內置Servlet容器、Tomcat、jetty,更多的好處只有上手了才知道java
二、構建
一、構建項目git
-
IntelliJ IDEA 能夠自行下載web
-
選擇構建Maven項目spring
-
選擇JDKspringboot
-
能夠直接點Next,不用去選擇構建類型app
maven
-
GroupId:公司域名倒序spring-boot
-
ArtifactId:項目名稱測試
-
Version:版本號,默認不用變code

二、引入springboot相關依賴
-
springboot父依賴 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.7.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent>
-
添加web支持 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
三、啓動類
-
@SpringBootApplication是springboot的核心註解
package com.test.controller; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class StartApplication { public static void main(String[] args) { SpringApplication.run(StartApplication.class, args); } }
-
寫一個controller
package com.test.controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloController { @RequestMapping(value = "hello", method = RequestMethod.GET) public String hello(){ return "My SpringBoot"; } }
三、啓動Springboot
啓動方法有不少種
-
直接運行啓動類的main方法
-
maven項目中

-
java -jar springboot1-1-0.0.1-SNAPSHOT.jar
-
其餘方式,能夠自行發掘
四、yml配置
springboot項目的基本配置文件放在resource目錄下,兩種方式,推薦yml
-
application.yml
-
application.properties
五、測試