mica-auto 介绍
mica-auto 代码自动生成
mica-auto 是 Spring cloud 微服务框架 Mica 中的一个基础组件,用来生成 Spring boot 的一些基础配置。
功能
生成 spring.factories
生成 spring-devtools.properties
生成 FeignClient 到 spring.factories 中,供 mica 中完成 Feign 自动化配置。
使用
maven
<dependency> <groupId>net.dreamlu</groupId> <artifactId>mica-auto</artifactId> <version>1.0.0</version> <scope>provided</scope> </dependency>
gradle >= 5.x
annotationProcessor(net.dreamlu:mica-auto:1.0.0)
gradle < 5.x
compileOnly net.dreamlu:mica-auto:1.0.0
原理
扫描 @Configuration,自动生成相应的配置。
注意: v1.0.0 已经支持组合注解。
初衷
在编写 Spring boot 相关插件的时候经常需要编写和修改 spring.factories
文件,其中有一次忘记修改,导致服务启动报错。想到编译期间自动生成这种配置。
开源协议
LGPL(GNU Lesser General Public
License)
参考
Google Auto: https://github.com/google/auto
Spring 5 - spring-context-indexer:https://github.com/spring-projects/spring- framework/tree/master/spring-context-indexer