# spring-boot-starter-ext **Repository Path**: wfhe/spring-boot-starter-ext ## Basic Information - **Project Name**: spring-boot-starter-ext - **Description**: No description available - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2017-01-09 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README 参考 http://www.jianshu.com/p/85460c1d835a 分析 正规的starter是一个独立的工程,然后在maven中新仓库注册发布,其他开发人员就可以使用你的starter了。 常见的starter会包括下面几个方面的内容: 自动配置文件,根据classpath是否存在指定的类来决定是否要执行该功能的自动配置。 spring.factories,非常重要,指导Spring Boot找到指定的自动配置文件。 endpoint:可以理解为一个admin,包含对服务的描述、界面、交互(业务信息的查询) health indicator:该starter提供的服务的健康指标 在应用程序启动过程中,Spring Boot使用SpringFactoriesLoader类加载器查找org.springframework.boot.autoconfigure.EnableAutoConfiguration关键字对应的Java配置文件。Spring Boot会遍历在各个jar包种META-INF目录下的spring.factories文件,构建成一个配置文件链表。除了EnableAutoConfiguration关键字对应的配置文件,还有其他类型的配置文件: org.springframework.context.ApplicationContextInitializer org.springframework.context.ApplicationListener org.springframework.boot.SpringApplicationRunListener org.springframework.boot.env.PropertySourceLoader org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider org.springframework.test.contex.TestExecutionListener Spring Boot的starter在编译时不需要依赖Spring Boot的库。这个例子中依赖spring boot并不是因为自动配置要用spring boot,而仅仅是因为需要实现CommandLineRunner接口。 两个需要注意的点 @ConditionalOnMissingBean的作用是:只有对应的ban在系统中都没有被创建,它修饰的初始化代码块才会执行,用户自己手动创建的bean优先; Spring Boot starter如何找到自动配置文件(xxxxAutoConfiguration之类的文件)? spring.factories:由Spring Boot触发探测classpath目录下的类,进行自动配置; @Enable:有时需要由starter的用户触发*查找自动配置文件的过程。