springboot
1入门
1.依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
2.主启动类
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
2.自动配置原理
1.SpringBoot特点
1.1 依赖管理
- 父项目依赖管理
依赖管理
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
的父项目
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.5.2</version>
</parent>
- 版本仲裁
- 不需要写版本号
- 也有特殊没有涵盖的需要写版本号
版本仲裁 基本涵盖了开发中的依赖版本
自定义修改版本时
<properties>
<activemq.version>5.16.2</activemq.version>
<antlr2.version>2.7.7</antlr2.version>
<appengine-sdk.version>1.9.89</appengine-sdk.version>
<artemis.version>2.17.0</artemis.version>
<aspectj.version>1.9.6</aspectj.version>
<assertj.version>3.19.0</assertj.version>
<atomikos.version>4.0.6</atomikos.version>
<awaitility.version>4.0.3</awaitility.version>
<build-helper-maven-plugin.version>3.2.0</build-helper-maven-plugin.version>
<byte-buddy.version>1.10.22</byte-buddy.version>
<caffeine.version>2.9.1</caffeine.version>
<cassandra-driver.version>4.11.2</cassandra-driver.version>
<classmate.version>1.5.1</classmate.version>
<commons-codec.version>1.15</commons-codec.version>
<commons-dbcp2.version>2.8.0</commons-dbcp2.version>
<commons-lang3.version>3.12.0</commons-lang3.version>
<commons-pool.version>1.6</commons-pool.version>
<commons-pool2.version>2.9.0</commons-pool2.version>
<couchbase-client.version>3.1.6</couchbase-client.version>
<db2-jdbc.version>11.5.5.0</db2-jdbc.version>
<dependency-management-plugin.version>1.0.11.RELEASE</dependency-management-plugin.version>
<derby.version>10.14.2.0</derby.version>
<dropwizard-metrics.version>4.1.24</dropwizard-metrics.version>
<ehcache.version>2.10.9.2</ehcache.version>
<ehcache3.version>3.9.4</ehcache3.version>
......
</properties>
自定义版本号
1.查看spring-boot-dependencies中规定的当前依赖的版本所用key
2.在当前项目里重写配置 maven就近依赖
<properties>
<mysql.version>8.0.25</mysql.version>
</properties>
starter场景启动器
- 1.spring-boot-starter-*
- 2.只要引入starter,这个场景的所有常规需要的依赖都自动引入。依赖传递原则
- SpringBoot所有支持的场景
- *-spring-boot-starter ,第三方开发的场景启动器
- 所有场景启动器最底层的依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.5.2</version>
<scope>compile</scope>
</dependency>