1.下載最新的Eclipse(老版本的有可能不包含springBoot插件),然后在help中打開Eclipse MarketPlace,在Spring Marketplace 中搜索SpringBoot,然后安裝(安裝過程比較慢)
2.點擊 I Agree……,然后,點擊Finish
3.安裝完成后,重啟eclipse
4.新增一個SpringBoot項目
5.點擊next,根據提示填寫相關項目信息,
6.點擊next,根據實際需要選擇依賴的選項,
7.點擊next,然后點擊finish按鈕,開始創建項目,第一次加載時因為需要聯網下載jar包,可能比較慢,慢慢等待即可。
我的工程創建完成后,pom.xml報錯了,Missing artifact mysql:mysql-connector-java:jar:8.0.15
解決方法:將maven倉庫下的mysql整個文件夾刪除,然后重新下載mysql相關的jar,就可以了。
創建完成的項目解決如下:
8.啟動項目
a.項目生成后會自動生成一個測試類TestSpringBootApplication.java,以Run As -> Spring Boot App方式運行,控制台出現以下界面即表示運行成功。
package com.example.testspringboot; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class TestSpringBootApplication { public static void main(String[] args) { SpringApplication.run(TestSpringBootApplication.class, args); } }
b.以頁面方式訪問hello world,則使用@RestController注解,新建測試類,TestController,並且添加hello方法
按照a運營springBoot項目后,直接在頁面訪問即可:http://localhost:8080/hello
TestController.java
package com.example.testspringboot; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @SpringBootApplication public class TestController { @RequestMapping("/hello") public String hello(){ return"Hello SpringBoot!"; } }