首页 > 其他 > 详细

flying中的AOP和IOC

时间:2016-09-02 00:44:24      阅读:184      评论:0      收藏:0      [点我收藏+]

技术分享

技术分享

 

注入属性:
private synchronized void injectReferenceServices() {
 if(this.injectReferenceServicesInitialized) return;
 PropertyDescriptor[] pds = PropertyUtils.getPropertyDescriptors(this.serviceClass);
 if(pds == null) return;
 for(PropertyDescriptor pd: pds) {
  Class<?> type = pd.getPropertyType();
  if(type == null) continue;
  if(type.getName().startsWith("java") || type.getName().startsWith("org"))  continue;
  if(module.getModuleConfig().getServiceConfigs().containsKey(type.getName())) {
   try {
    pd.getWriteMethod().invoke(this.serviceObject, new Object[]{module.getService(type)});
    logger.debug(this.serviceClass.getName()+" injectReferenceService ‘"+pd.getName()+"’success!");
   } catch (Exception e) {
    logger.error(this.serviceClass.getName()+" injectReferenceService ‘"+pd.getName()+"’失败,可能导致部分功能无法正常使用!", e);
   }
  }
 }
 this.injectReferenceServicesInitialized = true;
}

服务调用拦截:
public Object intercept(Object service, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
  。。。。。。。。。。。
   //
   if(!injectReferenceServicesInitialized) {
    this.injectReferenceServices();
   }
                    。。。。。。。
}
如似乎,一个不太完美的IOC实现了。

flying中的AOP和IOC

原文:http://www.cnblogs.com/hifong/p/5831796.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!