3、SpringBoot特点

文章目录

  • 1、依赖管理
    • 1.1、引入需要的jar包
    • 1.2、无需关注版本号,自动版本仲裁
    • 1.3、可以修改默认版本号
  • 2、开发导入starter场景启动器
  • 3、自动配置


【尚硅谷】SpringBoot2零基础入门教程-讲师:雷丰阳
笔记

路还在继续,梦还在期许

1、依赖管理

当前项目的父项目 pring-boot-starter-parent ,作用:依赖管理。


<parent>
    <groupId>org.springframework.bootgroupId>
    <artifactId>spring-boot-starter-parentartifactId>
    <version>2.3.4.RELEASEversion>
parent>

进入 spring-boot-starter-parent 项目,还有父项目 spring-boot-dependencies

<parent>
  <groupId>org.springframework.bootgroupId>
  <artifactId>spring-boot-dependenciesartifactId>
  <version>2.3.4.RELEASEversion>
parent>

进入spring-boot-dependencies 项目中 ,这个项目是真正管理SpringBoot应用中的所有依赖(SpringBoot 的版本仲裁中心),以后在导入依赖就会有默认版本(没有在dependencies里面管理的依赖还是需要写版本)。


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

1.1、引入需要的jar包

如果需要特定的jar包,只需要写坐标即可


dependencies>
    <dependency>
        <groupId>mysqlgroupId>
        <artifactId>mysql-connector-javaartifactId>
    dependency>
dependencies>

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

springboot管理的项目,不需要写版本号,自动版本仲裁。



1.3、可以修改默认版本号

当需要指定的版本号,可以修改



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

dependencies>
	<dependency>
	    <groupId>mysqlgroupId>
	    <artifactId>mysql-connector-javaartifactId>
	dependency>
dependencies>

2、开发导入starter场景启动器

spring-boot-starter-web

spring-boot-starter:SpringBoot的场景启动器。

web:web模块所需要的依赖。

<dependencies>
    
    <dependency>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-webartifactId>
        
    dependency>
dependencies>

starter是一组依赖的集合描述,只要引入一个starter,所需要的依赖jar包就会全部都导入进来,版本会根据父项目版本自动仲裁。


<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  
  
  
  
  
  <modelVersion>4.0.0modelVersion>
  <groupId>org.springframework.bootgroupId>
  <artifactId>spring-boot-starter-webartifactId>
  <version>2.3.4.RELEASEversion>
  <name>spring-boot-starter-webname>
  <description>Starter for building web, including RESTful, applications using Spring MVC. Uses Tomcat as the default embedded containerdescription>
  <url>https://spring.io/projects/spring-booturl>
  <organization>
    <name>Pivotal Software, Inc.name>
    <url>https://spring.iourl>
  organization>
  <licenses>
    <license>
      <name>Apache License, Version 2.0name>
      <url>https://www.apache.org/licenses/LICENSE-2.0url>
    license>
  licenses>
  <developers>
    <developer>
      <name>Pivotalname>
      <email>[email protected]email>
      <organization>Pivotal Software, Inc.organization>
      <organizationUrl>https://www.spring.ioorganizationUrl>
    developer>
  developers>
  <scm>
    <connection>scm:git:git://github.com/spring-projects/spring-boot.gitconnection>
    <developerConnection>scm:git:ssh://[email protected]/spring-projects/spring-boot.gitdeveloperConnection>
    <url>https://github.com/spring-projects/spring-booturl>
  scm>
  <issueManagement>
    <system>GitHubsystem>
    <url>https://github.com/spring-projects/spring-boot/issuesurl>
  issueManagement>
  <dependencies>
    <dependency>
      <groupId>org.springframework.bootgroupId>
      <artifactId>spring-boot-starterartifactId>
      <version>2.3.4.RELEASEversion>
      <scope>compilescope>
    dependency>
    <dependency>
      <groupId>org.springframework.bootgroupId>
      <artifactId>spring-boot-starter-jsonartifactId>
      <version>2.3.4.RELEASEversion>
      <scope>compilescope>
    dependency>
    <dependency>
      <groupId>org.springframework.bootgroupId>
      <artifactId>spring-boot-starter-tomcatartifactId>
      <version>2.3.4.RELEASEversion>
      <scope>compilescope>
    dependency>
    <dependency>
      <groupId>org.springframeworkgroupId>
      <artifactId>spring-webartifactId>
      <version>5.2.9.RELEASEversion>
      <scope>compilescope>
    dependency>
    <dependency>
      <groupId>org.springframeworkgroupId>
      <artifactId>spring-webmvcartifactId>
      <version>5.2.9.RELEASEversion>
      <scope>compilescope>
    dependency>
  dependencies>
project>

官网介绍






<dependency>
  <groupId>org.springframework.bootgroupId>
  <artifactId>spring-boot-starterartifactId>
  <version>2.7.3version>
  <scope>compilescope>
dependency>

3、自动配置

web场景启动器会自动 引入 所需要的依赖,比如Tomcat。

  • 自动配置Tomcat
    • 引入Tomcat依赖
    • 配置Tomcat
<dependency>
  <groupId>org.springframework.bootgroupId>
  <artifactId>spring-boot-starter-tomcatartifactId>
  <version>2.3.4.RELEASEversion>
  <scope>compilescope>
dependency>
  • 自动配好SpringMVC
    • 引入SpringMVC全套组件
    • 自动配好SpringMVC常用组件(功能)
  • 自动配好Web常见功能,如:字符编码问题
    • spring boot 帮我们配置好了所有web开发的常见场景
  • 默认的包结构
    • 主程序所在包及其下面的所有子包里面的组件都会被默认扫描进来
    • 无需以前的包扫描配置
    • 想要改变扫描路径,@SpringBootApplication(scanBasePackages=“com.atguigu”)
    • 或者@ComponentScan 指定扫描路径
@SpringBootApplication
// 等同于
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan("com.atguigu.boot")
  • 各种配置拥有默认值
    • 默认配置最终都是映射到某个类上,如:MultipartProperties
    • 配置文件的值最终会绑定每个类上,这个类会在容器中创建对象
  • 按需加载所有自动配置项
    • spring boot 有非常多的starter场景启动器
    • 引入了哪些场景,这个场景的自动配置才会开启
    • spring boot 所有的自动配置功能都在 spring-boot-autoconfigure 包里面

你可能感兴趣的:(SpringBoot,spring,boot,java,spring)