創(chuàng)建Spring boot項目
1.打開http://start.spring.io spring boot 官網(wǎng)弦赖,選擇一些配置項观挎,點擊Generate Project 導出spring boot的項目包。
2.解壓下載好的壓縮包搓扯,用eclipse 導入maven 項目,等待項目初始化,Spring boot 初始化完成后目錄結(jié)構(gòu)會變成這樣争群。
3.這樣Spring boot就算初始化完成了,從 SpringbootApplication 就可以啟動這個項目大年。
構(gòu)建web模塊
1.查看xml配置换薄,Spring boot 默認有兩個模塊:
<pre>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</pre>
核心模塊跟 test模塊
現(xiàn)在添加web模塊,添加了spring相關(guān)的一些模塊翔试,包括tomcat
<pre>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</pre>
2.測試一下web模塊:
<pre>
@RestController
public class TestController {
@RequestMapping("/test")
public String test(){
return "test";
}
</pre>
運行SpringbootApplication 會啟動內(nèi)置tomcat轻要,端口號為默認的8080,
在瀏覽器輸入http://localhost:8080/test
3.github地址: https://github.com/sunzhonghui/springboot