你的 Starter
主要内容
- autoconfigure 自动配置模块,包含自动配置代码
- starter 模块,包含指向自动配置模块(autoconfigure)的依赖及其他相关依赖
命名方式
- xxx-spring-boot-autoconfigure
- xxx-spring-boot-starter
加个前缀 和官方的区别出来
一些注意事项
- 不要使用 spring-boot 作为依赖的前缀
- 不要使用 spring-boot 的配置命名空间
- starter 中仅添加必要的依赖
- 声明对 spring-boot-starter 的依赖
例子
pom文件:
autoconfigure-demo:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>geektime.spring.hello</groupId>
<artifactId>geektime-spring-boot-starter</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
geektime-spring-boot-autoconfigure:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>spring.hello</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
geektime-spring-boot-starter:
<dependencies>
<dependency>
<groupId>geektime.spring.hello</groupId>
<artifactId>geektime-spring-boot-autoconfigure</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>spring.hello</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
运行结果![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/882f9a07093c8c8670e0c577dc1ec452.png)
结果不变。