-
public interface ResourceTypeLoader
自定义注入加载器public class CustomTypeLoader implements ResourceTypeLoader { @Override public Object load( ResourceFactory factory, String srcResourceName, Object srcObj, CustomConf annotation, Field field, Object attachment) { DataSource source = new DataMemorySource(resourceName); factory.register(resourceName, DataSource.class, source); if (field != null) { try { field.set(srcObj, source); } catch (Exception e) { e.printStackTrace(); } } return source; } @Override public Type resourceType() { return DataSource.class; } } public class InjectBean { @Resource(name = "platf") public DataSource source; } ResourceFactory factory = ResourceFactory.create(); factory.register(new CustomTypeLoader()); InjectBean bean = new InjectBean(); factory.inject(bean);
详情见: https://redkale.org
- 作者:
- zhangjx
-
-
方法概要
所有方法 实例方法 抽象方法 默认方法 修饰符和类型 方法 说明 default boolean
autoNone()
是否注入默认值null
返回true: 表示调用ResourceLoader之后资源仍不存在,则会在ResourceFactory里注入默认值null。Object
load(ResourceFactory factory, String srcResourceName, Object srcObj, String resourceName, Field field, Object attachment)
自定义的对象注入, 实现需要兼容Field为null的情况Type
resourceType()
注入加载器对应的类型
-
-
-
方法详细资料
-
load
Object load(ResourceFactory factory, @Nullable String srcResourceName, @Nullable Object srcObj, String resourceName, @Nullable Field field, @Nullable Object attachment)
自定义的对象注入, 实现需要兼容Field为null的情况- 参数:
factory
- ResourceFactorysrcResourceName
- 依附对象的资源名srcObj
- 资源依附对象resourceName
- 资源名field
- 字段对象attachment
- 附加对象- 返回:
- Object
-
resourceType
Type resourceType()
注入加载器对应的类型- 返回:
- 类型
-
autoNone
default boolean autoNone()
是否注入默认值null
返回true: 表示调用ResourceLoader之后资源仍不存在,则会在ResourceFactory里注入默认值null。
返回false: 表示资源不存在下次仍会调用ResourceTypeLoader
自行处理。- 返回:
- 是否注入默认值null
-
-