点滴记录,是前进的脚步 2017-09-08 03:56 采纳率: 20%
浏览 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 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)