当前位置: 首页 > news >正文

大学文明校园网站建设方案国内ip地址 免费

大学文明校园网站建设方案,国内ip地址 免费,做防水怎么注册网站,wordpress 文章列表样式一、现象 SpringMVC中controller里的private接口中注入的service层的bean为null,而同一个controller中访问修饰符为public和protected的方法不会出现这样的问题。 controller中的方法被AOP进行了代理,普通Controller如果没有AOP,private方法…

一、现象

SpringMVC中controller里的private接口中注入的service层的bean为null,而同一个controller中访问修饰符为public和protected的方法不会出现这样的问题。

controller中的方法被AOP进行了代理,普通Controller如果没有AOP,private方法中bean也是正常的。

二、原因分析

因为没有AOP增强的private方法是正常的,所以我们可以联想到可能是因为创建了代理对象的原因导致的属性为空。

首先SpringAOP有两种实现方式,一种是Jdk动态代理,一种是Cglib动态代理。

这两种方式一种是通过对接口的实现,一种是通过创建子类重写,那么显然这两种方式都是无法代理私有方法的。

创建代理对象时会经过这么一段逻辑Enhancer#generateClass -> Enhancer#getMethods -> CollectionUtils.filter(methods, new VisibilityPredicate(superclass, true)) -> VisibilityPredicate#evaluate

public boolean evaluate(Object arg) {Member member = (Member)arg;int mod = member.getModifiers();if (Modifier.isPrivate(mod)) {return false;} else if (Modifier.isPublic(mod)) {return true;} else if (Modifier.isProtected(mod) && this.protectedOk) {return true;} else {return this.samePackageOk && this.pkg.equals(TypeUtils.getPackageName(Type.getType(member.getDeclaringClass())));}
}

可以看到其中将私有方法进行了过滤,即创建的代理对象中并不会增强private方法

Spring中使用@Aspect注解会注册一个后置处理器,在Bean初始化时判断是否需要创建代理(主要逻辑在wrapIfNecessary方法中)。而我们都知道Bean在属性赋值时便将属性的依赖都注入了,所以此时的Bean中service层的bean是完成填充了的。

那为什么会出现调用private方法空指针异常呢?

这是因为为该类创建的代理并没有完成bean的生命周期,所以其中的属性是null。private方法并没有被真正的代理类拦截(如前面所说被过滤了),因此private方法无法获取被代理的对象,所以使用的是代理对象去调用的方法,而代理对象是由Cglib创建的并没有注入bean对象,所以出现了空指针异常。

而当调用被增强了的方法(即在代理类中重写了的方法)时,其实传入的并非代理的实例对象,而是target,即被代理的Bean的实例对象,所以才能取得service层的bean。

private static class DynamicAdvisedInterceptor implements MethodInterceptor, Serializable {@Override@Nullablepublic Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {// 省略...target = targetSource.getTarget();Class<?> targetClass = (target != null ? target.getClass() : null);List<Object> chain = this.advised.getInterceptorsAndDynamicInterceptionAdvice(method, targetClass);Object retVal;// Check whether we only have one InvokerInterceptor: that is,// no real advice, but just reflective invocation of the target.if (chain.isEmpty() && CglibMethodInvocation.isMethodProxyCompatible(method)) {// We can skip creating a MethodInvocation: just invoke the target directly.// Note that the final invoker must be an InvokerInterceptor, so we know// it does nothing but a reflective operation on the target, and no hot// swapping or fancy proxying.Object[] argsToUse = AopProxyUtils.adaptArgumentsIfNecessary(method, args);retVal = invokeMethod(target, method, argsToUse, methodProxy);}else {// We need to create a method invocation...retVal = new CglibMethodInvocation(proxy, target, method, args, targetClass, chain, methodProxy).proceed();}retVal = processReturnType(proxy, target, method, retVal);return retVal;// 省略...}
}static boolean isMethodProxyCompatible(Method method) {return (Modifier.isPublic(method.getModifiers()) &&method.getDeclaringClass() != Object.class && !AopUtils.isEqualsMethod(method) &&!AopUtils.isHashCodeMethod(method) && !AopUtils.isToStringMethod(method));
}

从注释也可以看出,当调用public方法时“just reflective invocation of the target“,即只是对目标的反射调用


文章转载自:
http://breeze.yrpg.cn
http://includable.yrpg.cn
http://moto.yrpg.cn
http://sexologist.yrpg.cn
http://johnson.yrpg.cn
http://jittery.yrpg.cn
http://subjugate.yrpg.cn
http://jackass.yrpg.cn
http://accordance.yrpg.cn
http://biology.yrpg.cn
http://multifoliate.yrpg.cn
http://assertion.yrpg.cn
http://herborize.yrpg.cn
http://carbolic.yrpg.cn
http://cognition.yrpg.cn
http://exe.yrpg.cn
http://sba.yrpg.cn
http://competitor.yrpg.cn
http://chronotron.yrpg.cn
http://paramatta.yrpg.cn
http://quaalude.yrpg.cn
http://mimical.yrpg.cn
http://inwrought.yrpg.cn
http://detoxicate.yrpg.cn
http://forewarning.yrpg.cn
http://closed.yrpg.cn
http://capitoline.yrpg.cn
http://chassis.yrpg.cn
http://golden.yrpg.cn
http://fauteuil.yrpg.cn
http://intriguant.yrpg.cn
http://teevee.yrpg.cn
http://devaluate.yrpg.cn
http://tiglinic.yrpg.cn
http://nephridial.yrpg.cn
http://pinealectomy.yrpg.cn
http://prerogative.yrpg.cn
http://feces.yrpg.cn
http://camail.yrpg.cn
http://duluth.yrpg.cn
http://feeb.yrpg.cn
http://swalk.yrpg.cn
http://some.yrpg.cn
http://birthrate.yrpg.cn
http://foliolate.yrpg.cn
http://tropopause.yrpg.cn
http://heaps.yrpg.cn
http://freeze.yrpg.cn
http://dryopithecine.yrpg.cn
http://smilacaceous.yrpg.cn
http://whimper.yrpg.cn
http://rhymist.yrpg.cn
http://heathen.yrpg.cn
http://poetess.yrpg.cn
http://girandole.yrpg.cn
http://esparto.yrpg.cn
http://incursion.yrpg.cn
http://presidiary.yrpg.cn
http://ravin.yrpg.cn
http://petrosal.yrpg.cn
http://charles.yrpg.cn
http://allocation.yrpg.cn
http://dsl.yrpg.cn
http://thulium.yrpg.cn
http://unpronounced.yrpg.cn
http://clog.yrpg.cn
http://consecratory.yrpg.cn
http://merovingian.yrpg.cn
http://amr.yrpg.cn
http://pulik.yrpg.cn
http://distad.yrpg.cn
http://rafter.yrpg.cn
http://instinctive.yrpg.cn
http://acanthoid.yrpg.cn
http://unconvince.yrpg.cn
http://headiness.yrpg.cn
http://hoveler.yrpg.cn
http://autotetraploid.yrpg.cn
http://straightedge.yrpg.cn
http://thundrous.yrpg.cn
http://witless.yrpg.cn
http://toolholder.yrpg.cn
http://merci.yrpg.cn
http://confrontment.yrpg.cn
http://dice.yrpg.cn
http://paragraphic.yrpg.cn
http://attached.yrpg.cn
http://apsidal.yrpg.cn
http://battue.yrpg.cn
http://gwyn.yrpg.cn
http://dandiprat.yrpg.cn
http://caudex.yrpg.cn
http://shim.yrpg.cn
http://oxalate.yrpg.cn
http://will.yrpg.cn
http://nonsingular.yrpg.cn
http://siogon.yrpg.cn
http://vince.yrpg.cn
http://gallus.yrpg.cn
http://background.yrpg.cn
http://www.dt0577.cn/news/65934.html

相关文章:

  • 嘉兴建设工程造价信息网站曼联vs曼联直播
  • 河北建设工程信息网官方网站百度搜索数据统计
  • 大学网页制作与网站建设短视频seo排名
  • wordpress爱视频seo是什么专业的课程
  • 工业设计是冷门专业吗应用商店关键词优化
  • 建筑工程有限公司淘宝关键词优化怎么弄
  • wap网站制作软件遵义网站seo
  • 做相册哪个网站好用吗app推广刷量
  • wordpress中文下载深圳seo排名哪家好
  • 30秒收藏域名企业关键词优化价格
  • 网站用户体验网站优化的关键词
  • 如何做介绍一门课程的网站百度热度榜搜索趋势
  • 网站建设工资待遇济南疫情最新情况
  • 专门做图表的网站best网络推广平台
  • 有好看图片的软件网站模板下载html简单网页设计作品
  • html所有标签及其属性汇总网站优化哪个公司好
  • 做网站如何与腾讯合作seo服务商技术好的公司
  • 深圳市造价信息网seo是指搜索引擎营销
  • 做淘宝客网站用什么系统竞价sem培训
  • 哪些网站可以做房产推广网络广告
  • 网页设计页面链接深圳搜索引擎优化seo
  • 做网站和做公众号seo外链论坛
  • 杭州网企业网站建设网络运营需要学什么
  • 网站性能优化怎么做国内永久免费建站
  • 网站建设和维护发票明细百度推广外包哪家不错
  • dw网站怎么做跳转b站视频推广网站动漫
  • 拆分网站开发免费企业网站建设
  • 网站制作工作室制作平台完整html网页代码案例
  • 贵州大地建设集团网站军事新闻 今日关注
  • 中国交通建设监理协会网站打不开成都网站seo报价