本文将介绍如何使用自定义注解加载配置文件中的信息给类中的属性赋值
- 定义注解
- 定义@LoadProperty注解,用来加载配置文件
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @description 加载配置文件,value传入文件路径,与@{ConfigField}配套使用
* @author xujiali
* @date 2019-09-12 4:03:22 PM
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface LoadProperty {
String value(); //配置文件(.properties)路径
}
- 定义@ConfigField注解,用来给属性赋值
import java.lang.annotation.Documente