点滴记录,是前进的脚步 2017-09-08 03:56 采纳率: 16.7%
浏览 857
已采纳

springAOP使用问题求教

最近在网上学SpringAOP的使用,自己模仿网上的博文写程序,其中配置文件如下:
<?xml version="1.0" encoding="UTF-8"?>
《beans xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"

xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.2.xsd">

通知/目标方法被拦截前后的具体操作内容
《bean id="helper" class="aop.Helper"></bean》

定义切点(事件发生地点)
《bean id="cutPoint" class="org.springframework.aop.support.JdkRegexpMethodPointcut">
《property name="pattern" value=".*targetMethod"> /bean>

关联切点和通知
《bean id="advisorWithCutpoint" class="org.springframework.aop.support.DefaultPointcutAdvisor">
《property name="cutPoint" ref="cutPoint">《/property>
《property name="advisor" ref="helper">《/property>
《/bean>

配置代理
《bean id="proxy" class="org.springframework.aop.framework.ProxyFactoryBean">
《property name="target" ref="target">《/property>
《property name="cutFace" value="advisorWithCutpoint">《/property>
《property name="targetInterface" value="aop.TargetInterface">《/property>
《/bean>
运行时程序报错:Bean property 'cutPoint' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
这个错涉及到的bean是配置文件中 ”关联切点和通知 ”部分的。很明显是没有注入cutPoint引起的,但是advisorWithCutpoint对应的类是个框架中的类org.springframework.aop.support.DefaultPointcutAdvisor,自己不能修改,怎么将cutPoint注入到框架类中呢?(自定义类可以在其中写get方法或使用注解注入,但这个是往框架类中注入bean,怎么注入呢?)

  • 写回答

4条回答 默认 最新

  • 砸死接触 2017-09-08 05:03
    关注

    楼主是不是写错了? 不是应该

      <property name="advice" ref=" helper "/>
      <property name="pointcut" ref="cutPoint" />
    
    

    ?????

    property里的name 看错误 是没有那个参数啊 !!!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog