隨着動態語言的流行(Ruby.Grooy.Scala.Nodejs),Java的開發顯得格外的笨重: 繁多的配置、低下的開發效率、複雜的部署流程以及第三方技術集成難度大。
在上述環境下,SpringBoot應運而生。它使用「習慣優於配置」(項目中存在大量的配置,此外還內置一個習慣性的配置,讓你無須手動進行配置) 的理念讓你的項目快速運行起來。使用SpringBoot很容易建立一個獨立運行(運行jar,內嵌Servlet容器)準生產級別的基於Sring框架的項目,使用SpringBoot你能夠不用或者只須要不多的Spring配置。java
優勢
(1) 快速構建項目;
(2) 對主流開發框架的無配置集成;
(3) 項目可獨立運行,無須外部依賴Servlet容器;
(4) 提供運行時的應用監控;
(5) 極大地提升了開發、部署效率:
(6) 與雲計算的自然集成。web
缺點
(1) 書籍文檔較少且不夠深刻。
(2) 若是你不認同Spring框架,這也許是它的缺點,但建議你必定要使用Spring框架。spring
新建project ,選擇Spring Initializr,選擇jdk,點擊next瀏覽器
須要修改如下幾個參數tomcat
Group:組名app
artifact::項目名框架
java version:jdk版本maven
packaging:打包方式,若是是web項目打war包,若是不是打成jar包。ide
點擊nextspring-boot
根據須要選擇須要的依賴,咱們此時暫時不選擇,點擊next。
設置工程的名稱和路徑,點擊finish完成。
注意:項目新建成功以後maven配置是idea默認的,因此要檢查是否須要修改。
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.10.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent>
說明:Spring boot的項目必需要將parent設置爲spring boot的parent,該parent包含了大量默認的配置,大大簡化了咱們的開發。
<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>
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </dependency>
@Controller public class StudentController { @RequestMapping("hello") @ResponseBody public String hello(){ return "Hello Spring Boot!"; } }
運行效果:
若看到以上效果則項目啓動成功,此時tomcat默認端口8080。
打開瀏覽器,輸入localhost:8080/hello,若出現如下效果則成功。