定制自己的起步依赖

你的 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>

运行结果在这里插入图片描述

结果不变。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值