創(chuàng)建Spring boot項目
1.打開http://start.spring.io spring boot 官網(wǎng),選擇一些配置項,點擊Generate Project 導(dǎo)出spring boot的項目包。
2.解壓下載好的壓縮包,用eclipse 導(dǎo)入maven 項目,等待項目初始化,Spring boot 初始化完成后目錄結(jié)構(gòu)會變成這樣。
3.這樣Spring boot就算初始化完成了,從 SpringbootApplication 就可以啟動這個項目。
構(gòu)建web模塊
1.查看xml配置,Spring boot 默認(rèn)有兩個模塊:
<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,端口號為默認(rèn)的8080,
在瀏覽器輸入http://localhost:8080/test
3.github地址: https://github.com/sunzhonghui/springboot