AnnotatedElementUtils 类
获取某个类的某个方法上是否有标注注解,并可以通过其他 API 获取到这个类注解上的属性值,该工具类其他 API 下面截图可以查看。
public static boolean isBeanAnnotated(Method method) {
return AnnotatedElementUtils.hasAnnotation(method, Bean.class);
}
ReflectionUtils 类
反射工具类,可以获取到 Class 上的方法对象,属性对象,进而反射调用,其他 API 下面截图可以查看。
@Nullable
public static Field findField(Class<?> clazz, String name) {
return findField(clazz, name, null);
}
private static Field[] getDeclaredFields(Class<?> clazz) {
return result;
}
ConfigurationClassParser 扫描类
配置类扫描器,在自定义包扫描的时候可以用到该类,parse() 方法非常有用。
ConfigurationClassParser parser = new ConfigurationClassParser(
this.metadataReaderFactory, this.problemReporter, this.environment,
this.resourceLoader, this.componentScanBeanNameGenerator, registry);
parser.parse(candidates);
ClassPathBeanDefinitionScanner 扫描类
这个也是对类路径下的类的扫描器,在自定义类扫描器的时候也可以用这个类,重写 doScan() ,入参指定要扫描类的包路径即可。推荐使用这个,方便快捷。
scanner.doScan(String...basePackages);
ComponentScanAnnotationParser 扫描类
这个包扫描器就是针对 @Component 注解的扫描了,也可以利用此类自定义包扫描器,以上三个都是可用来自定义类扫描器的工具类。
componentScanParser.parse(AnnotationAttributes componentScan, final String declaringClass)
AnnotationAttributes 类
此类可以获取到某个注解上所有配置的值。
AnnotationAttributes.fromMap(metadataReader.getAnnotationAttributes(DBMaster.class.getName())));
ResourceLoaderAware 类
此类可以用来获取文件资源加载器 Resource,有了这个对象就可以对整个工程下的文件进行 IO 流读取。从而加载到内存中提供使用。所有的.class 文件也是通过该类可用获取到。
PropertiesLoaderUtils 类
针对 Properties 文件的工具类,加载配置文件,提供简单 API 获取属性值。
Properties properties = PropertiesLoaderUtils.loadAllProperties("abc.properties");
String key666 = properties.getProperty("key666");
System.out.println("key666 = " + key666);
AopUtils 类
AOP 工具类,可以找到具体目标实现类方法,有时候可能是因为中间会有桥接方法,所以用下面这个工具类的 getMostSpecificMethod() 方法就可以轻松找到桥接的具体方法。
Method m = AopUtils.getMostSpecificMethod(method,targetClass)
AnnotationUtils
获取某个具体方法上的注解属性值。
AnnotationUtils.getAnnotation(spcMethod, DBMaster.class)