Spring Boot (基礎篇):Spring Boot知識點總結
Spring Boot簡介
- SpringBoot 以便捷開發、快速部署著稱。設計目的是用來簡化新Spring應用的初始搭建以及開發過程。
- SpringBoot 致力於簡潔,讓開發者寫更少的配置,程式能夠更快的執行和啟動
- SpringBoot 設計原則就是 約定優於配置。並且內嵌了Servlet容器
- SpringBoot 採用的是Java Config的方式,對Spring進行配置,避免了XML配置以及複雜的依賴管理,使用springboot可以幫助開發者快速搭建一個Spring框架
- SpringBoot 封裝了各種元件,使用那個就引入依賴模組即可
- SpringBoot 使用了特定的方式來進行配置,從而使開發人員不再需要定義樣板化的配置。
- SpringBoot 可以以jar包的形式來執行,執行一個Spring Boot專案我們只需要通過Java -jar xx.jar類執行。
- SpringBoot 可以內嵌Tomcat,這樣我們無需以war包的形式部署專案,非常方便。
Spring Boot啟動器
1)spring-boot-starter 這是Spring Boot的核心啟動器,包含了自動配置、日誌和YAML。
2)spring-boot-starter-actuator 幫助監控和管理應用。
3)spring-boot-starter-amqp 通過spring-rabbit來支援AMQP協議(Advanced Message Queuing Protocol)。
4)spring-boot-starter-aop 支援面向方面的程式設計即AOP,包括spring-aop和AspectJ。
5)spring-boot-starter-artemis 通過Apache Artemis支援JMS的API(Java Message Service API)。
6)spring-boot-starter-batch 支援Spring Batch,包括HSQLDB資料庫。
7)spring-boot-starter-cache 支援Spring的Cache抽象。
8)spring-boot-starter-cloud-connectors 支援Spring Cloud Connectors,簡化了在像Cloud Foundry或Heroku這樣的雲平臺上連線服務。
9)spring-boot-starter-data-elasticsearch 支援ElasticSearch搜尋和分析引擎,包括spring-data-elasticsearch。
10)spring-boot-starter-data-gemfire 支援GemFire分散式資料儲存,包括spring-data-gemfire。
11)spring-boot-starter-data-jpa 支援JPA(java Persistence API),包括spring-data-jpa、spring-orm、hibernate。
12)spring-boot-starter-data-MongoDB 支援mongodb資料,包括spring-data-mongodb。
13)spring-boot-starter-data-rest 通過spring-data-rest-webmvc,支援通過REST暴露Spring Data資料倉庫。
14)spring-boot-starter-data-solr 支援Apache Solr搜尋平臺,包括spring-data-solr。
15)spring-boot-starter-freemarker 支援FreeMarker模板引擎。
16)spring-boot-starter-groovy-templates 支援Groovy模板引擎。
17)spring-boot-starter-hateoas 通過spring-hateoas支援基於HATEOAS的RESTful Web服務。
18)spring-boot-starter-hornetq 通過HornetQ支援JMS。
19)spring-boot-starter-integration 支援通用的spring-integration模組。
20)spring-boot-starter-jdbc 支援JDBC資料庫。
21)spring-boot-starter-jersey 支援Jersey RESTful Web服務框架。
22)spring-boot-starter-jta-atomikos 通過Atomikos支援JTA分散式事務處理。
23)spring-boot-starter-jta-bitronix 通過Bitronix支援JTA分散式事務處理。
24)spring-boot-starter-mail 支援javax.mail模組。
25)spring-boot-starter-mobile 支援spring-mobile。
26)spring-boot-starter-mustache 支援Mustache模板引擎。
27)spring-boot-starter-Redis 支援redis鍵值儲存資料庫,包括spring-redis。
28)spring-boot-starter-security 支援spring-security。
29)spring-boot-starter-social-facebook 支援spring-social-facebook
30)spring-boot-starter-social-linkedin 支援pring-social-linkedin
31)spring-boot-starter-social-twitter 支援pring-social-twitter
32)spring-boot-starter-test 支援常規的測試依賴,包括JUnit、Hamcrest、Mockito以及spring-test模組。
33)spring-boot-starter-thymeleaf 支援Thymeleaf模板引擎,包括與Spring的整合。
34)spring-boot-starter-velocity 支援Velocity模板引擎。
35)spring-boot-starter-web 支援全棧式Web開發,包括Tomcat和spring-webmvc。
36)spring-boot-starter-websocket 支援WebSocket開發。
37)spring-boot-starter-ws 支援Spring Web Services。
Springboot註解
@SpringBootApplication:包含了@ComponentScan、@Configuration和@EnableAutoConfiguration註解。其中@ComponentScan讓spring Boot掃描到Configuration類並把它加入到程式上下文。
@Configuration:等同於spring的XML配置檔案;使用Java程式碼可以檢查型別安全。
@EnableAutoConfiguration:自動配置。
@ComponentScan:元件掃描,可自動發現和裝配一些Bean。
@Component:可配合CommandLineRunner使用,在程式啟動後執行一些基礎任務。
@RestController:註解是@Controller和@ResponseBody的合集,表示這是個控制器bean,並且是將函式的返回值直 接填入HTTP響應體中,是REST風格的控制器。
@Autowired:自動匯入。
@PathVariable:獲取引數。
@JsonBackReference:解決巢狀外鏈問題。
@RepositoryRestResourcepublic:配合spring-boot-starter-data-rest使用。
@EnableAutoConfiguration:Spring Boot自動配置(auto-configuration):嘗試根據你新增的jar依賴自動配置你的Spring應用。例如,如果你的classpath下存在HSQLDB,並且你沒有手動配置任何資料庫連線beans,那麼我們將自動配置一個記憶體型(in-memory)資料庫”。你可以將@EnableAutoConfiguration或者@SpringBootApplication註解新增到一個@Configuration類上。這個註釋告訴SpringBoot“猜”你將如何想配置Spring,基於你已經新增jar依賴項。如果spring-boot-starter-web已經新增Tomcat和Spring MVC,這個註釋自動將假設您正在開發一個web應用程式並新增相應的spring設定。動配置被設計用來和“Starters”一起更好的工作,但這兩個概念並不直接相關。您可以自由挑選starter依賴項以外的jar包,springboot仍將盡力自動配置您的應用程式。
@Bean:相當於XML中的bean,放在方法的上面,而不是類,意思是產生一個bean,並交給spring管理。