Auto Service
Auto Service
实现自动生成META-INF/services
文件的功能,减少配置文件的编写,除了支持 JAVA 标准的 SPI,也支持类似于 Dubbo 扩展 SPI 方式。
Usage
Import Dependency
<dependency>
<groupId>org.ifinal.auto</groupId>
<artifactId>auto-service</artifactId>
<version>${latest.version}</version>
</dependency>
Java SPI
package org.ifinal.auto.service;
@AutoProcessor
@SupportedOptions({"debug", "verify"})
@SupportedSourceVersion(SourceVersion.RELEASE_8)
@SupportedAnnotationTypes("*")
public class MyProcessor extends AbstractProcessor {
@Override
public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment roundEnv) {
return false;
}
}
编译后在会生成配置文件META-INF/serivces/javax.annotation.processing.Processor
org.ifinal.auto.service.MyProcessor
Dubbo SPI
package org.ifinal.auto.service;
@AutoService(value = Filter.class, path = "dubbo", name = "myFilter")
public class MyFilter implements Filter {
@Override
public Result invoke(final Invoker<?> invoker, final Invocation invocation) throws RpcException {
return null;
}
}
编译后在会生成配置文件META-INF/dubbo/org.apache.dubbo.rpc.Filter
,内容如下:
myFilter=org.ifinal.auto.service.MyFilter