-
- 类型参数:
T
- Annotation
public interface ResourceAnnotationLoader<T extends Annotation>
自定义注入加载器@Documented @Target({FIELD}) @Retention(RUNTIME) public @interface CustomConf { String path(); } public class CustomConfAnnotationLoader implements ResourceAnnotationLoader<CustomConf> { @Override public void load( ResourceFactory factory, String srcResourceName, Object srcObj, CustomConf annotation, Field field, Object attachment) { try { field.set(srcObj, new File(annotation.path())); } catch (Exception e) { e.printStackTrace(); } System.out.println("对象是 src =" + srcObj + ", path=" + annotation.path()); } @Override public Class<CustomConf> annotationType() { return CustomConf.class; } } public class InjectBean { @CustomConf(path = "conf/test.xml") public File conf; } ResourceFactory factory = ResourceFactory.create(); factory.register(new CustomConfAnnotationLoader()); InjectBean bean = new InjectBean(); factory.inject(bean);
详情见: https://redkale.org
- 从以下版本开始:
- 2.8.0
- 作者:
- zhangjx