SpringBoot基本配置

入口類和@SpringBootApplication

  @SpringBootApplication是Spring Boot的核心註解,是一個組合註解,部分源碼以下:java

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(excludeFilters = {
@Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),
@Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) })
public @interface SpringBootApplication 

  • 它的核心功能由@EnableAutoConfiguration註解提供,@EnableAutoConfiguration讓Spring Boot根據類中的jar包依賴爲當前項目進行自動配置
  • Spring Boot會自動掃描@SpringBootApplication註解所在類的同級包以及下級包中的Bean

關閉特定的自動配置

經過@SpringBootApplication註解下的exclude參數如:web

@SpringBootApplication(exclude={DataSourceAutoConfigration.class})redis

 

 

定製Banner

Spring Boot啓動會有一個默認圖案,這個圖案 能夠自定義, 自定義方式以下spring

在src/main/resource下新建一個banner.txt文件mongodb

經過http://patorjk.com/software/taag/這個網站生成字符數據庫

將生成的字符粘貼到banner.txt文件中便可編程

關閉banner能夠修改入口類websocket

SpringApplication app = new SpringApplication(DemoApplication.class);

    app.setBannerMode(Banner.Mode.OFF);

    app.run(args);

 

starter pom

  Spring Boot提供了不少starter pom方便進行maven配置,下面是一些常見的starter:mvc

  

名稱app

描述

spring-boot-starter

核心Spring Boot starter,包括自動配置支持,日誌和YAML

spring-boot-starter-actuator

生產準備的特性,用於幫咱們監控和管理應用

spring-boot-starter-amqp

對」高級消息隊列協議」的支持,經過spring-rabbit實現

spring-boot-starter-aop

對面向切面編程的支持,包括spring-aop和AspectJ

spring-boot-starter-batch

對Spring Batch的支持,包括HSQLDB數據庫

spring-boot-starter-cloud-connectors

對Spring Cloud Connectors的支持,簡化在雲平臺下(例如,Cloud Foundry 和Heroku)服務的鏈接

spring-boot-starter-data-elasticsearch

對Elasticsearch搜索和分析引擎的支持,包括spring-data-elasticsearch

spring-boot-starter-data-gemfire

對GemFire分佈式數據存儲的支持,包括spring-data-gemfire

spring-boot-starter-data-jpa

對」Java持久化API」的支持,包括spring-data-jpa,spring-orm和Hibernate

spring-boot-starter-data-mongodb

對MongoDB NOSQL數據庫的支持,包括spring-data-mongodb

spring-boot-starter-data-rest

對經過REST暴露Spring Data倉庫的支持,經過spring-data-rest-webmvc實現

spring-boot-starter-data-solr

對Apache Solr搜索平臺的支持,包括spring-data-solr

spring-boot-starter-freemarker

對FreeMarker模板引擎的支持

spring-boot-starter-groovy-templates

對Groovy模板引擎的支持

spring-boot-starter-hateoas

對基於HATEOAS的RESTful服務的支持,經過spring-hateoas實現

spring-boot-starter-hornetq

對」Java消息服務API」的支持,經過HornetQ實現

spring-boot-starter-integration

對普通spring-integration模塊的支持

spring-boot-starter-jdbc

對JDBC數據庫的支持

spring-boot-starter-jersey

對Jersey RESTful Web服務框架的支持

spring-boot-starter-jta-atomikos

對JTA分佈式事務的支持,經過Atomikos實現

spring-boot-starter-jta-bitronix

對JTA分佈式事務的支持,經過Bitronix實現

spring-boot-starter-mail

對javax.mail的支持

spring-boot-starter-mobile

對spring-mobile的支持

spring-boot-starter-mustache

對Mustache模板引擎的支持

spring-boot-starter-redis

對REDIS鍵值數據存儲的支持,包括spring-redis

spring-boot-starter-security

對spring-security的支持

spring-boot-starter-social-facebook

對spring-social-facebook的支持

spring-boot-starter-social-linkedin

對spring-social-linkedin的支持

spring-boot-starter-social-twitter

對spring-social-twitter的支持

spring-boot-starter-test

對經常使用測試依賴的支持,包括JUnit, Hamcrest和Mockito,還有spring-test模塊

spring-boot-starter-thymeleaf

對Thymeleaf模板引擎的支持,包括和Spring的集成

spring-boot-starter-velocity

對Velocity模板引擎的支持

spring-boot-starter-web

對全棧web開發的支持, 包括Tomcat和spring-webmvc

spring-boot-starter-websocket

對WebSocket開發的支持

spring-boot-starter-ws

對Spring Web服務的支持

 

 

注:本文是我的學習筆記,以上內容均來自《JavaEE開發的顛覆者 Spring Boot實戰》一書

相關文章
相關標籤/搜索