How mica-auto Simplifies Spring Boot Starter Creation with Annotation Processors
The article introduces mica-auto, a Spring Cloud component that uses annotation processing to automatically generate starter configurations, SPI entries, and Feign client setups, and provides usage examples for Maven and Gradle along with recent updates.
1. Introduction
mica-auto (Spring boot starter tool) is a basic component of the Mica Spring Cloud microservice framework, used to generate basic configuration for Spring boot starters.
2. Principle
mica-auto uses an Annotation Processor, a feature present since JDK 1.6. The processor scans annotations at compile time and can generate Java code automatically, similar to Lombok.
3. Features
Automatically generate spring.factories and spring-devtools.properties configurations.
Generate FeignClient entries into spring.factories for automatic Feign configuration in mica-cloud.
Generate Java SPI configuration by adding the
@AutoServiceannotation.
4. 2.x Update Log
Added AutoConfigDataLocationResolver.
Added AutoConfigDataLoader.
Added AutoEnableCircuitBreaker.
Upgraded Spring Boot to 2.4.1 (non‑mandatory, no compatibility issues).
5. Usage
Note:If your project uses Lombok, place the mica-auto dependency after Lombok.
5.1 Maven
<code><dependency>
<groupId>net.dreamlu</groupId>
<artifactId>mica-auto</artifactId>
<version>2.0.3</version>
<scope>provided</scope>
</dependency>
</code>5.2 Gradle ≥ 5.x
<code>annotationProcessor("net.dreamlu:mica-auto:2.0.3")</code>5.3 Gradle < 5.x
<code>compileOnly "net.dreamlu:mica-auto:2.0.3"</code>5.4 Java SPI example
Add the
@AutoServiceannotation and specify the SPI interface
Processor.class.
<code>package foo.bar;
import javax.annotation.processing.Processor;
@AutoService(Processor.class)
public class MyProcessor implements Processor {
// …
}
</code>AutoService will automatically generate the SPI configuration file
META-INF/services/javax.annotation.processing.Processorcontaining:
<code>foo.bar.MyProcessor</code>6. Mica Ecosystem
mica (Spring Cloud microservice component set): https://gitee.com/596392912/mica
mica-auto (Spring boot starter tool): https://gitee.com/596392912/mica-auto
mica-weixin (JFinal Weixin Spring boot starter): https://gitee.com/596392912/mica-weixin
mica-mqtt (MQTT component based on t‑io): https://gitee.com/596392912/mica-mqtt
Spring Cloud HTTP/2 solution (h2c): https://gitee.com/596392912/spring-cloud-java11
Follow the author’s Gitee page for more Java open‑source components: https://gitee.com/596392912
Java Architecture Diary
Committed to sharing original, high‑quality technical articles; no fluff or promotional content.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.