模块 org.redkale

注释类型 ResourceInjected


  • @Documented
    @Target(METHOD)
    @Retention(RUNTIME)
    public @interface ResourceInjected
    @Resource资源被依赖注入时的监听事件。
    本注解只能标记在空参数或者(String、Object、java.lang.reflect.Field)三个参数类型的任意组合方法上
    方法在资源被依赖注入后调用。
     public class ResourceService implements Service {
    
        @Resource(name = "res.id")
        private int id;
    
        @Resource(name = "res.name")
        private String name;
    
        @ResourceInjected
        private void onInjected(Object dest, String fieldName) {
           System.out .println("资源被注入到对象(" + dest + ")的字段(" + fieldName + ")上");
      }
     }
    
     public class RecordService implements Service {
    
        @Resource
        private ResourceService resService;
    
        public void test() {
      }
    
      public static void main(String[] args) throws Exception {
          ResourceFactory factory = ResourceFactory.create();
          factory.register("res.id", "2345");
          factory.register("res.name", "my old name");
          ResourceService res = new ResourceService();
          factory.inject(res);
          factory.register("", res);
          RecordService serice = new RecordService();
          factory.inject(record);
      }
     }
     

    详情见: https://redkale.org

    作者:
    zhangjx