項目用到的環境:web
選擇類型爲Spring Initializer.spring
接着下一步, 選擇web.json
再下一步, 選擇項目的路徑, 點擊完成app
新建成的項目的文件目錄結構以下圖:spring-boot
pom.xml以下所示:測試
<dependencies>
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies>
其中, spring-boot-starter-web是支持web的模塊, spring-boot-starter-test是支持測試的模塊.spa
添加一個HelloWorldController以下:code
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloWorldController { @RequestMapping("/") public String index(){ return "Hello World"; } }
@RestController表示裏邊的方法都以json格式輸出, 無需再添加額外的json配置.xml
點擊Shift + F10 或者直接點擊運行, 待項目啓動成功後, 訪問http://localhost:8080ci
如圖即表示第一個spring boot項目啓動成功.