簡介
關於依賴
springboot父級依賴
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
這塊配置就是Spring Boot父級依賴,有了這個,當前的項目就是Spring Boot項目了,spring-boot-starter-parent是一個特殊的starter,它用來提供相關的Maven默認依賴,使用它之後,常用的包依賴可以省去version標籤,我是你們的爸爸啊,所以我直接給你version信息就可以了(繼承)。
起步依賴 spring-boot-starter-xx
Spring Boot Maven插件
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
功能:
-
把項目打包成一個可執行的超級JAR(uber-JAR),包括把應用程序的所有依賴打入JAR文件內,併爲JAR添加一個描述文件,其中的內容能讓你用java -jar來運行應用程序。
-
搜索public static void main()方法來標記爲可運行類。
spring-boot-starter-logging以及應用日誌
<build>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</build>
那也就意味着我們的SpringBoot應用自動使用logback作爲日誌框架,在啓動的時候,由org.springframework.boot.logging.LoggingApplicationListener根據情況初始化並使用。默認情況下,SpringBoot已經給我們提供好了很多默認的日誌配置,我們只需要將spring-boot-starter-logging作爲依賴加入到你的SpringBoot應用就可以了,但是如果我們要對這些默認配置進行定製,可以有兩種方式進行:
-
遵守logback的約定,在classpath中使用定製化的logback.xml配置文件。
-
在文件系統中任意一個地方提供自己的logback.xml配置文件,然後通過如下配置來application.properties中指定我們日誌系統配置文件位置:
logging.config=/{your config file location}}/logback.xml
如果我們已經習慣了log4j或log4j2,那我們只需要把spring-boot-starter-logging換成如下的starter就好。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j</artifactId>
</dependency>
或
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
用於快速構建web應用的spring-boot-starter-web
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
引入依賴之後呢,我們可以得到一個直接執行的web應用,然後我們運行mvn spring-boot:run,就能直接啓動一個基於嵌入式Tomcat容器的web應用了,然後就可以通過controller來供用戶訪問了。
SpringBoot的spring-boot-starter
-
spring-boot-starter-logging :使用 Spring Boot 默認的日誌框架 Logback。
-
spring-boot-starter-log4j :添加 Log4j 的支持。
-
spring-boot-starter-web :支持 Web 應用開發,包含 Tomcat 和 spring-mvc。
-
spring-boot-starter-tomcat :使用 Spring Boot 默認的 Tomcat 作爲應用服務器。
-
spring-boot-starter-jetty :使用 Jetty 而不是默認的 Tomcat 作爲應用服務器。
-
spring-boot-starter-test :包含常用的測試所需的依賴,如 JUnit、Hamcrest、Mockito 和 spring-test 等。
-
spring-boot-starter-aop :包含 spring-aop 和 AspectJ 來支持面向切面編程(AOP)。
-
spring-boot-starter-security :包含 spring-security。
-
spring-boot-starter-jdbc :支持使用 JDBC 訪問數據庫。
-
spring-boot-starter-redis :支持使用 Redis。
-
spring-boot-starter-data-mongodb :包含 spring-data-mongodb 來支持 MongoDB。
-
spring-boot-starter-data-jpa :包含 spring-data-jpa、spring-orm 和 Hibernate 來支持 JPA。
-
spring-boot-starter-amqp :通過 spring-rabbit 支持 AMQP。
-
spring-boot-starter-actuator : 添加適用於生產環境的功能,如性能指標和監測等功能。