-
@Deprecated(since="2.8.0") @Documented @Target(METHOD) @Retention(RUNTIME) public @interface ResourceListener
已过时。replaced byResourceChanged
@Resource资源被更新时的监听事件, 本注解只能标记在方法参数为ResourceEvent[]上
注意: 一个类只能存在一个@ResourceListener的方法, 多余的会被忽略
方法在资源被更新以后调用。public class RecordService implements Service { @Resource(name = "record.id") private int id; @Resource(name = "record.name") private String name; @ResourceListener private void changeResource(ResourceEvent[] events) { for(ResourceEvent event : events) { System.out .println("@Resource = " + event.name() + " 资源变更: newVal = " + event.newValue() + ", oldVal = " + event.oldValue()); } } public static void main(String[] args) throws Exception { ResourceFactory factory = ResourceFactory.create(); factory.register("record.id", "2345"); factory.register("record.name", "my old name"); Record record = new Record(); factory.inject(record); factory.register("record.name", "my new name"); } }
详情见: https://redkale.org
- 作者:
- zhangjx
- 另请参阅:
ResourceChanged
-
-
可选元素概要
可选元素 修饰符和类型 可选元素 说明 boolean
different
已过时。新旧值是否不同时才回调方法
true: 新值与旧值不同时才回调ResourceListener方法 false: 只要执行了ResourceFactory.register 就回调ResourceListener方法
-