76 lines
1.6 KiB
Java
76 lines
1.6 KiB
Java
/*
|
|
*
|
|
*/
|
|
package org.redkale.inject;
|
|
|
|
import java.lang.annotation.Annotation;
|
|
import java.lang.reflect.Field;
|
|
|
|
/**
|
|
* 自定义注入加载器
|
|
*
|
|
* <blockquote>
|
|
* <pre>
|
|
*
|
|
* @Documented
|
|
* @Target({FIELD})
|
|
* @Retention(RUNTIME)
|
|
* public @interface CustomConf {
|
|
* String path();
|
|
* }
|
|
*
|
|
*
|
|
* public class CustomConfProvider 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;
|
|
* }
|
|
*
|
|
*
|
|
* </pre>
|
|
* </blockquote>
|
|
*
|
|
* <p>详情见: https://redkale.org
|
|
*
|
|
* @since 2.8.0
|
|
* @author zhangjx
|
|
* @param <T> Annotation
|
|
*/
|
|
public interface ResourceAnnotationLoader<T extends Annotation> {
|
|
|
|
public void load(
|
|
ResourceFactory factory,
|
|
String srcResourceName,
|
|
Object srcObj,
|
|
T annotation,
|
|
Field field,
|
|
Object attachment);
|
|
|
|
public Class<T> annotationType();
|
|
}
|