A list,

Mica-auto (Spring Boot Stater development tool) is a basic component in the Spring Cloud microservice framework MICA, which is used to generate some basic configurations of Spring Boot Starter.

Second, the principle of

Mica Auto uses the Annotation Processor, which is not new and has been around since JDK 1.6. The Annotation Processor is a javAC tool that scans and processes annotations at compile time. The Annotation Processor can obtain information about annotations and annotated objects, and then automatically generate Java code according to annotations, eliminating manual compilation and improving coding efficiency. Lombok famously uses this technique as well.

Three, functionality,

  • Automatically generates spring.factories and spring-devtools.properties.
  • Generate FeignClient into Spring. factories for automatic Feign configuration in mica-Cloud.
  • Generate Java SPI configuration, need to add@AutoServiceAnnotation.
annotations Spring. Factories or Spi key
@AutoContextInitializer ApplicationContextInitializer
@AutoListener ApplicationListener
@AutoRunListener SpringApplicationRunListener
@AutoEnvPostProcessor EnvironmentPostProcessor
@AutoFailureAnalyzer FailureAnalyzer
@AutoConfigImportFilter AutoConfigurationImportFilter
@AutoTemplateProvider TemplateAvailabilityProvider
@AutoEnableCircuitBreaker EnableCircuitBreaker
@AutoConfigDataLocationResolver ConfigDataLocationResolver
@AutoConfigDataLoader ConfigDataLoader
@Component EnableAutoConfiguration
@AutoIgnore Ignore and do not generate to spring.factories
@AutoService Generate the Java SPI configuration

Iv. 2.x Update records

  • Add AutoConfigDataLocationResolver.
  • Add AutoConfigDataLoader.
  • Add AutoEnableCircuitBreaker.
  • Upgrade Spring Boot to 2.4.1 (non-mandatory dependency, no compatibility issues).

Fifth, use

Note: If you use Lombok in your project, place the mica-Auto dependency after Lombok.

5.1 the maven

<dependency>
  <groupId>net.dreamlu</groupId>
  <artifactId>mica-auto</artifactId>
  <version>The 2.0.3</version>
  <scope>provided</scope>
</dependency>
Copy the code

5.2 gradle > = 5. X

annotationProcessor("Net. Dreamlu: mica - auto: 2.0.3")
Copy the code

5.3 gradle < 5. X

compileOnly "Net. Dreamlu: mica - auto: 2.0.3"
Copy the code

5.4 Java SPI Example:

Add annotation @autoService specifying the SPI interface processor.class.

package foo.bar;

import javax.annotation.processing.Processor;

@AutoService(Processor.class)  
public class MyProcessor implements Processor {
/ /...
}
Copy the code

AutoService spi will automatically generate configuration file meta-inf/services/javax.mail annotation. Processing. The Processor. Content:

foo.bar.MyProcessor
Copy the code

6. Mica Ecology

  • Mica (Spring Cloud Microservices Component Set): gitee.com/596392912/m…

  • Mica-auto (Spring Boot starter): gitee.com/596392912/m…

  • Mica-weixin (Spring Boot starter for jfinal Weixin) : gitee.com/596392912/m…

  • Mica-mqtt (MQTT component based on T-IO implementation) : gitee.com/596392912/m…

  • Spring Cloud Microservices Http2 Solution (H2C) : gitee.com/596392912/s…