zoukankan      html  css  js  c++  java
  • SpringAop对struts2的Action设置切面织入时报错java.lang.NoSuchMethodException

    学习springAop,尝试对struts2的Action层使用Aop切面实现日志的打印。

    执行出现报错:java.lang.NoSuchMethodException.

    查阅资料解决办法:spring中配置<aop:config proxy-target-class="true"/> ,强制使用cglib代理。

    分析问题原因:

      springAop实现默认使用java动态代理技术(基于接口的代理),当springbean没有实现接口时使用cglib代理(基于继承代理)。

    sturts2中Action我这里使用的是继承于ActionSupport,而ActionSupport有实现Action,Validateable等接口。故springAop会使用

    动态代理生成Action的代理类,而Action中的接口中自然没有声名业务方法的接口,所以会报找不到方法的错误。修改spring配置

    强制使用cglib代理,基于继承生成Action的代理方法,是可以访问到Action中任何公有方法。

  • 相关阅读:
    springMVC
    自动装配
    HTTP Status 500
    this compilation unit is not on the build of a java project
    Struct2提交表单数据到Acion
    ResultMap
    MyEclipse 代码自动提示
    xe mysql
    java Study 基础 1
    InterfaceConnect
  • 原文地址:https://www.cnblogs.com/xiejinjie/p/9224692.html
Copyright © 2011-2022 走看看