IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> Java知识库 -> 基础入门--了解自动配置原理【上】 -> 正文阅读

[Java知识库]基础入门--了解自动配置原理【上】

上篇:基础入门--SpringBoot2程序

1、SpringBoot特点

1.1、依赖管理

自定义引入的依赖管理

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.4.RELEASE</version>
</parent>

我们在父pom文件点击进去查看发现,又有一个父项目?

?其实在这个父项目底层发现:几乎声明了所有开发中常用的依赖的版本号,自动版本仲裁机制

如:

<properties>
    <activemq.version>5.15.13</activemq.version>
    <antlr2.version>2.7.7</antlr2.version>
    <appengine-sdk.version>1.9.82</appengine-sdk.version>
    <artemis.version>2.12.0</artemis.version>
    <aspectj.version>1.9.6</aspectj.version>
    <assertj.version>3.16.1</assertj.version>
    <atomikos.version>4.0.6</atomikos.version>
    <awaitility.version>4.0.3</awaitility.version>
    <bitronix.version>2.1.4</bitronix.version>
    <build-helper-maven-plugin.version>3.1.0</build-helper-maven-plugin.version>
    <byte-buddy.version>1.10.14</byte-buddy.version>
    <caffeine.version>2.8.5</caffeine.version>
    <cassandra-driver.version>4.6.1</cassandra-driver.version>
    <classmate.version>1.5.1</classmate.version>
    <commons-codec.version>1.14</commons-codec.version>
    <commons-dbcp2.version>2.7.0</commons-dbcp2.version>
    <commons-lang3.version>3.10</commons-lang3.version>
    <commons-pool.version>1.6</commons-pool.version>
    <commons-pool2.version>2.8.1</commons-pool2.version>
    <couchbase-client.version>3.0.8</couchbase-client.version>
    <db2-jdbc.version>11.5.4.0</db2-jdbc.version>
    <dependency-management-plugin.version>1.0.10.RELEASE</dependency-management-plugin.version>
    <derby.version>10.14.2.0</derby.version>
    <dropwizard-metrics.version>4.1.12.1</dropwizard-metrics.version>
    <ehcache.version>2.10.6</ehcache.version>
    <ehcache3.version>3.8.1</ehcache3.version>
    <elasticsearch.version>7.6.2</elasticsearch.version>
    <embedded-mongo.version>2.2.0</embedded-mongo.version>
    <exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
    <flatten-maven-plugin.version>1.2.5</flatten-maven-plugin.version>
    <flyway.version>6.4.4</flyway.version>
    <freemarker.version>2.3.30</freemarker.version>
    <git-commit-id-plugin.version>3.0.1</git-commit-id-plugin.version>
    <glassfish-el.version>3.0.3</glassfish-el.version>
    <glassfish-jaxb.version>2.3.3</glassfish-jaxb.version>
    <groovy.version>2.5.13</groovy.version>
    <gson.version>2.8.6</gson.version>
    <h2.version>1.4.200</h2.version>
    <hamcrest.version>2.2</hamcrest.version>
    <hazelcast.version>3.12.9</hazelcast.version>
    <hazelcast-hibernate5.version>1.3.2</hazelcast-hibernate5.version>
    <hibernate.version>5.4.21.Final</hibernate.version>
    <hibernate-validator.version>6.1.5.Final</hibernate-validator.version>
    <hikaricp.version>3.4.5</hikaricp.version>
    <hsqldb.version>2.5.1</hsqldb.version>
    <htmlunit.version>2.40.0</htmlunit.version>
    <httpasyncclient.version>4.1.4</httpasyncclient.version>
    <httpclient.version>4.5.12</httpclient.version>
    <httpcore.version>4.4.13</httpcore.version>
    <infinispan.version>10.1.8.Final</infinispan.version>
    <influxdb-java.version>2.18</influxdb-java.version>
    <jackson-bom.version>2.11.2</jackson-bom.version>
    <jakarta-activation.version>1.2.2</jakarta-activation.version>
    <jakarta-annotation.version>1.3.5</jakarta-annotation.version>
    <jakarta-jms.version>2.0.3</jakarta-jms.version>
    <jakarta-json.version>1.1.6</jakarta-json.version>
    <jakarta-json-bind.version>1.0.2</jakarta-json-bind.version>
    <jakarta-mail.version>1.6.5</jakarta-mail.version>
    <jakarta-persistence.version>2.2.3</jakarta-persistence.version>
    <jakarta-servlet.version>4.0.4</jakarta-servlet.version>
    <jakarta-servlet-jsp-jstl.version>1.2.7</jakarta-servlet-jsp-jstl.version>
    <jakarta-transaction.version>1.3.3</jakarta-transaction.version>
    <jakarta-validation.version>2.0.2</jakarta-validation.version>
    <jakarta-websocket.version>1.1.2</jakarta-websocket.version>
    <jakarta-ws-rs.version>2.1.6</jakarta-ws-rs.version>
    <jakarta-xml-bind.version>2.3.3</jakarta-xml-bind.version>
    <jakarta-xml-soap.version>1.4.2</jakarta-xml-soap.version>
    <jakarta-xml-ws.version>2.3.3</jakarta-xml-ws.version>
    <janino.version>3.1.2</janino.version>
    <javax-activation.version>1.2.0</javax-activation.version>
    <javax-annotation.version>1.3.2</javax-annotation.version>
    <javax-cache.version>1.1.1</javax-cache.version>
    <javax-jaxb.version>2.3.1</javax-jaxb.version>
    <javax-jaxws.version>2.3.1</javax-jaxws.version>
    <javax-jms.version>2.0.1</javax-jms.version>
    <javax-json.version>1.1.4</javax-json.version>
    <javax-jsonb.version>1.0</javax-jsonb.version>
    <javax-mail.version>1.6.2</javax-mail.version>
    <javax-money.version>1.0.3</javax-money.version>
    <javax-persistence.version>2.2</javax-persistence.version>
    <javax-transaction.version>1.3</javax-transaction.version>
    <javax-validation.version>2.0.1.Final</javax-validation.version>
    <javax-websocket.version>1.1</javax-websocket.version>
    <jaxen.version>1.2.0</jaxen.version>
    <jaybird.version>3.0.9</jaybird.version>
    <jboss-logging.version>3.4.1.Final</jboss-logging.version>
    <jboss-transaction-spi.version>7.6.0.Final</jboss-transaction-spi.version>
    <jdom2.version>2.0.6</jdom2.version>
    <jedis.version>3.3.0</jedis.version>
    <jersey.version>2.30.1</jersey.version>
    <jetty-el.version>8.5.54</jetty-el.version>
    <jetty-jsp.version>2.2.0.v201112011158</jetty-jsp.version>
    <jetty-reactive-httpclient.version>1.1.4</jetty-reactive-httpclient.version>
    <jetty.version>9.4.31.v20200723</jetty.version>
    <jmustache.version>1.15</jmustache.version>
    <johnzon.version>1.2.8</johnzon.version>
    <jolokia.version>1.6.2</jolokia.version>
    <jooq.version>3.13.4</jooq.version>
    <json-path.version>2.4.0</json-path.version>
    <json-smart.version>2.3</json-smart.version>
    <jsonassert.version>1.5.0</jsonassert.version>
    <jstl.version>1.2</jstl.version>
    <jtds.version>1.3.1</jtds.version>
    <junit.version>4.13</junit.version>
    <junit-jupiter.version>5.6.2</junit-jupiter.version>
    <kafka.version>2.5.1</kafka.version>
    <kotlin.version>1.3.72</kotlin.version>
    <kotlin-coroutines.version>1.3.8</kotlin-coroutines.version>
    <lettuce.version>5.3.4.RELEASE</lettuce.version>
    <liquibase.version>3.8.9</liquibase.version>
    <log4j2.version>2.13.3</log4j2.version>
    <logback.version>1.2.3</logback.version>
    <lombok.version>1.18.12</lombok.version>
    <mariadb.version>2.6.2</mariadb.version>
    <maven-antrun-plugin.version>1.8</maven-antrun-plugin.version>
    <maven-assembly-plugin.version>3.3.0</maven-assembly-plugin.version>
    <maven-clean-plugin.version>3.1.0</maven-clean-plugin.version>
    <maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
    <maven-dependency-plugin.version>3.1.2</maven-dependency-plugin.version>
    <maven-deploy-plugin.version>2.8.2</maven-deploy-plugin.version>
    <maven-enforcer-plugin.version>3.0.0-M3</maven-enforcer-plugin.version>
    <maven-failsafe-plugin.version>2.22.2</maven-failsafe-plugin.version>
    <maven-help-plugin.version>3.2.0</maven-help-plugin.version>
    <maven-install-plugin.version>2.5.2</maven-install-plugin.version>
    <maven-invoker-plugin.version>3.2.1</maven-invoker-plugin.version>
    <maven-jar-plugin.version>3.2.0</maven-jar-plugin.version>
    <maven-javadoc-plugin.version>3.2.0</maven-javadoc-plugin.version>
    <maven-resources-plugin.version>3.1.0</maven-resources-plugin.version>
    <maven-shade-plugin.version>3.2.4</maven-shade-plugin.version>
    <maven-source-plugin.version>3.2.1</maven-source-plugin.version>
    <maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
    <maven-war-plugin.version>3.2.3</maven-war-plugin.version>
    <micrometer.version>1.5.5</micrometer.version>
    <mimepull.version>1.9.13</mimepull.version>
    <mockito.version>3.3.3</mockito.version>
    <mongodb.version>4.0.5</mongodb.version>
    <mssql-jdbc.version>7.4.1.jre8</mssql-jdbc.version>
    <mysql.version>8.0.21</mysql.version>
    <nekohtml.version>1.9.22</nekohtml.version>
    <neo4j-ogm.version>3.2.16</neo4j-ogm.version>
    <netty.version>4.1.52.Final</netty.version>
    <netty-tcnative.version>2.0.34.Final</netty-tcnative.version>
    <nio-multipart-parser.version>1.1.0</nio-multipart-parser.version>
    <oauth2-oidc-sdk.version>7.1.1</oauth2-oidc-sdk.version>
    <nimbus-jose-jwt.version>8.19</nimbus-jose-jwt.version>
    <ojdbc.version>19.3.0.0</ojdbc.version>
    <okhttp3.version>3.14.9</okhttp3.version>
    <oracle-database.version>19.3.0.0</oracle-database.version>
    <pooled-jms.version>1.1.2</pooled-jms.version>
    <postgresql.version>42.2.16</postgresql.version>
    <prometheus-pushgateway.version>0.9.0</prometheus-pushgateway.version>
    <quartz.version>2.3.2</quartz.version>
    <querydsl.version>4.3.1</querydsl.version>
    <r2dbc-bom.version>Arabba-SR7</r2dbc-bom.version>
    <rabbit-amqp-client.version>5.9.0</rabbit-amqp-client.version>
    <reactive-streams.version>1.0.3</reactive-streams.version>
    <reactor-bom.version>Dysprosium-SR12</reactor-bom.version>
    <rest-assured.version>3.3.0</rest-assured.version>
    <rsocket.version>1.0.2</rsocket.version>
    <rxjava.version>1.3.8</rxjava.version>
    <rxjava-adapter.version>1.2.1</rxjava-adapter.version>
    <rxjava2.version>2.2.19</rxjava2.version>
    <saaj-impl.version>1.5.2</saaj-impl.version>
    <selenium.version>3.141.59</selenium.version>
    <selenium-htmlunit.version>2.40.0</selenium-htmlunit.version>
    <sendgrid.version>4.4.8</sendgrid.version>
    <servlet-api.version>4.0.1</servlet-api.version>
    <slf4j.version>1.7.30</slf4j.version>
    <snakeyaml.version>1.26</snakeyaml.version>
    <solr.version>8.5.2</solr.version>
    <spring-amqp.version>2.2.11.RELEASE</spring-amqp.version>
    <spring-batch.version>4.2.4.RELEASE</spring-batch.version>
    <spring-data-releasetrain.version>Neumann-SR4</spring-data-releasetrain.version>
    <spring-framework.version>5.2.9.RELEASE</spring-framework.version>
    <spring-hateoas.version>1.1.2.RELEASE</spring-hateoas.version>
    <spring-integration.version>5.3.2.RELEASE</spring-integration.version>
    <spring-kafka.version>2.5.6.RELEASE</spring-kafka.version>
    <spring-ldap.version>2.3.3.RELEASE</spring-ldap.version>
    <spring-restdocs.version>2.0.5.RELEASE</spring-restdocs.version>
    <spring-retry.version>1.2.5.RELEASE</spring-retry.version>
    <spring-security.version>5.3.4.RELEASE</spring-security.version>
    <spring-session-bom.version>Dragonfruit-SR1</spring-session-bom.version>
    <spring-ws.version>3.0.10.RELEASE</spring-ws.version>
    <sqlite-jdbc.version>3.31.1</sqlite-jdbc.version>
    <sun-mail.version>1.6.5</sun-mail.version>
    <thymeleaf.version>3.0.11.RELEASE</thymeleaf.version>
    <thymeleaf-extras-data-attribute.version>2.0.1</thymeleaf-extras-data-attribute.version>
    <thymeleaf-extras-java8time.version>3.0.4.RELEASE</thymeleaf-extras-java8time.version>
    <thymeleaf-extras-springsecurity.version>3.0.4.RELEASE</thymeleaf-extras-springsecurity.version>
    <thymeleaf-layout-dialect.version>2.4.1</thymeleaf-layout-dialect.version>
    <tomcat.version>9.0.38</tomcat.version>
    <unboundid-ldapsdk.version>4.0.14</unboundid-ldapsdk.version>
    <undertow.version>2.1.4.Final</undertow.version>
    <versions-maven-plugin.version>2.7</versions-maven-plugin.version>
    <webjars-hal-browser.version>3325375</webjars-hal-browser.version>
    <webjars-locator-core.version>0.45</webjars-locator-core.version>
    <wsdl4j.version>1.6.3</wsdl4j.version>
    <xml-maven-plugin.version>1.0.2</xml-maven-plugin.version>
    <xmlunit2.version>2.7.0</xmlunit2.version>
  </properties>

?以上是底层引用的pom文件,后续开发,我们就不需要关注版本问题,其实在这个pom文件里面,版本问题springboot帮我们做好了

开发导入starter场景启动器

(1)见到很多 spring-boot-starter-* : *就某种场景

(2)只要引入starter,这个场景的所有常规需要的依赖我们都自动引入

(3)SpringBoot所有支持的场景

https://docs.spring.io/spring-boot/docs/current/reference/html/using-spring-boot.html#using-boot-starter

(4)见到的 *-spring-boot-starter: 第三方为我们提供的简化开发的场景启动器。

(5)所有场景启动器最底层的依赖

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter</artifactId>
  <version>2.3.4.RELEASE</version>
  <scope>compile</scope>
</dependency>

无需关注版本号,自动版本仲裁

  • 引入依赖默认都可以不写版本
  • 引入非版本仲裁的jar,要写版本号。

可以修改默认版本号

(1)看spring-boot-dependencies里面规定当前依赖的版本 用的 key

(2)在当前项目里面重写配置

<properties>
        <mysql.version>5.1.43</mysql.version>
    </properties>

1.2、自动配置

  • 自动配好Tomcat
  • 配置Tomcat
  • <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-tomcat</artifactId>
          <version>2.3.4.RELEASE</version>
          <scope>compile</scope>
        </dependency>

(1)自动配好SpringMVC

  • 引入SpringMVC全套组件
  • 自动配好SpringMVC常用组件(功能)

(2)自动配好Web常见功能,如:字符编码问题

  • SpringBoot帮我们配置好了所有web开发的常见场景

?(3)默认的包结构

  • 主程序所在包及其下面的所有子包里面的组件都会被默认扫描进来
  • 无需以前的包扫描配置
  • 想要改变扫描路径,@SpringBootApplication(scanBasePackages="org.apache.springboot
    ")? ?或者@ComponentScan 指定扫描路径
  • @SpringBootApplication
    等同于
    @SpringBootConfiguration
    @EnableAutoConfiguration
    @ComponentScan("org.apache.springboot")

    若想查看容器里面信息,直接在启动类编写该代码,直接启动运行即可:

?打印输出信息:

测试发现:控制层类可以跟启动类同一个目录?

postman测试运行结果如下:

当然,若想要改变扫描路,可以采取@SpringBootApplication(scanBasePackages="org.apache.springboot
")? ?或者@ComponentScan 指定扫描路径

@SpringBootApplication注解里面看到

?上图,这三个核心注解相当于@SpringBootApplication注解做替换

(4)各种配置拥有默认值

  • 默认配置最终都是映射到某个类上,如:MultipartProperties
  • 配置文件的值最终会绑定每个类上,这个类会在容器中创建对象

?(5)按需加载所有自动配置项

  • 非常多的starter
  • 引入了哪些场景这个场景的自动配置才会开启,比如:
  •  <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-batch</artifactId>
                <scope>compile</scope>
            </dependency>

  • SpringBoot所有的自动配置功能都在 spring-boot-autoconfigure 包里面
  Java知识库 最新文章
计算距离春节还有多长时间
系统开发系列 之WebService(spring框架+ma
springBoot+Cache(自定义有效时间配置)
SpringBoot整合mybatis实现增删改查、分页查
spring教程
SpringBoot+Vue实现美食交流网站的设计与实
虚拟机内存结构以及虚拟机中销毁和新建对象
SpringMVC---原理
小李同学: Java如何按多个字段分组
打印票据--java
上一篇文章      下一篇文章      查看所有文章
加:2021-08-22 13:25:07  更:2021-08-22 13:26:22 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/23 9:04:09-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码