前言
Spring Boot是Spring 官方的頂級項目之一,她的其他小伙伴還有Spring Cloud尘应、Spring Framework惶凝、Spring Data等等,本文并不是Spring Boot的詳細使用教程犬钢,而是帶領(lǐng)你去簡單的認識她苍鲜,然后通過指南的形式分享關(guān)于她的優(yōu)秀資源,讓你能夠更好的使用她娜饵,并且本指南將會持續(xù)更新~
簡介
官方原文: Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run". We take an opinionated view of the Spring platform and third-party libraries so you can get started with minimum fuss. Most Spring Boot applications need very little Spring configuration.
譯:Spring Boot可以輕松創(chuàng)建單獨的坡贺,基于生產(chǎn)級的Spring應(yīng)用程序,您需要做的可能“僅僅是去運行”箱舞。 我們提供了Spring Platform對Spring 框架和第三方庫進行處理,盡可能的降低使用的復(fù)雜度拳亿。大多數(shù)情況下Spring Boot應(yīng)用只需要非常少的配置晴股。
Features(她的特點)
- Create stand-alone Spring applications
- Embed Tomcat, Jetty or Undertow directly (no need to deploy WAR files)
快速構(gòu)建獨立的Spring Application,使用內(nèi)嵌容器肺魁,無需部署到外部容器电湘,你要做的僅僅是運行她。 - Provide opinionated 'starter' POMs to simplify your Maven configuration
- Automatically configure Spring whenever possible
提供眾多擴展的‘starter’鹅经,通過依賴探知自動配置寂呛,你要做的僅僅是添加Maven依賴。 - Provide production-ready features such as metrics, health checks and externalized configuration
提供生產(chǎn)環(huán)境下的性能健康狀態(tài)監(jiān)控及外部化配置瘾晃,讓你時刻掌控她贷痪。 - Absolutely no code generation and no requirement for XML configuration
無需生成代碼及XML配置,一切從簡蹦误。
通過上面官網(wǎng)的描述劫拢,其實我總結(jié)下來就兩條:
- 依賴探知肉津,自動配置
- 一切從簡,Just Run !
嘗試
- 配置你項目的pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
- 創(chuàng)建Application.java
@RestController
@EnableAutoConfiguration
public class Application {
@RequestMapping("/")
String index() {
return "Welcome to know Spring Boot !";
}
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
- Just Run舱沧,執(zhí)行
Application.main()
或者 mvn:spring-boot:run
啟動成功后妹沙,訪問http://localhost:8080/
可能僅僅不到1分鐘便可快速構(gòu)建、部署熟吏、啟動一個Web 應(yīng)用距糖,這就是Spring Boot ~
下面是Spring Boot官方關(guān)于構(gòu)建Web項目的項目結(jié)構(gòu)建議,你可以根據(jù)實際情況調(diào)整~
src
com
+- example
+- myproject
+- Application.java //建議位于項目的根目錄牵寺,這可以簡化@ComponentScan
|
+- domain
| +- Customer.java
| +- CustomerRepository.java
|
+- service
| +- CustomerService.java
|
+- web
+- CustomerController.java
resources
+-config//配置文件
application.properties
+-static//靜態(tài)文件
+-css
+-js
+-images
index.html
+-templates//模板文件
pom.xml
指南
-
文檔
- Spring Boot 官方文檔
- Spring Boot 官方文檔中文翻譯版 | EPUB離線版下載
- Spring MVC 4.2.4 官方文檔中文翻譯版
- Spring Security 4.1 官方文檔中文翻譯版
-
Spring Data JPA 1.4.3 官方文檔中文翻譯版
(關(guān)于學(xué)習(xí)新框架肾筐、產(chǎn)品我的建議是最好去閱讀官方文檔,因為一手的東西永遠比二手的好缸剪,再者Spring的文檔一向做的非常優(yōu)秀)
-
優(yōu)秀學(xué)習(xí)資源
- 泥瓦匠 - Springboot-learning-example
- Catoop - Spring Boot 學(xué)習(xí)
- 程序猿DD - Spring Boot基礎(chǔ)教程
- Liaokailin - Spring Boot 實戰(zhàn)教程
- 梁桂釗 - Spring Boot 揭秘與實戰(zhàn) 系列
- Spring Boot 筆記(Word)
-
Spring Boot&Spring Cloud專題
(這些是我為了編寫本文而在網(wǎng)上找尋的優(yōu)秀系列教程吗铐、文集,都相當不錯杏节,值得你去閱讀~至于書籍就不作推薦了唬渗,我覺得計算機類書籍除了一些經(jīng)典的、具有指導(dǎo)思想的奋渔、概念理論性的書籍值得閱讀外镊逝,在這個技術(shù)極速迭代的時代去消耗時間閱讀這類書籍是不理智的)