最近在网上学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,怎么注入呢?)
楼主是不是写错了? 不是应该
<property name="advice" ref=" helper "/>
<property name="pointcut" ref="cutPoint" />
?????
property里的name 看错误 是没有那个参数啊 !!!
《bean id="cutPoint" class="org.springframework.aop.support.JdkRegexpMethodPointcut">多注意下这个
题主的想法是像个框架中的某个类,,的某个方法做一个切面???
做法应该和给自己类设置切面类似,,不过题主这种设置方法看起来好变扭。。
往框架类中注入bean,怎么注入呢?
理论上和自定义的一样
但是框架中可能有些类,你注入一个,框架在给注入一个,覆盖了,
自己不能修改 可以继承这个类 在添加自己修改的东西 再注入你写好的类