在Spring的ApplicationContext中为了避免客户端代码直接引用目标Bean,可以将目标Bean定义成内部Bean,我在其中是这样配置的
<bean id="service"
class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces">
<value>org.spring.aop.target.TestService</value>
</property>
<property name="target">
<bean class="org.spring.aop.advice.AuthorityInterceptor"/>
<!-- <ref local="serviceTarget" /> -->
</property>
<property name="interceptorNames">
<list>
<value>authorityInterceptor</value>
</list>
</property>
</bean>
出现如下错误:
Exception in thread "main" org.springframework.aop.AopInvocationException: AOP configuration seems to be invalid: tried calling method [public abstract void org.spring.aop.target.TestService.view()] on target [org.spring.aop.advice.AuthorityInterceptor@1193779]; nested exception is java.lang.IllegalArgumentException: object is not an instance of declaring class
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:203)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:162)
at org.spring.aop.advice.AuthorityInterceptor.invoke(AuthorityInterceptor.java:21)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:209)
at $Proxy0.view(Unknown Source)
at org.spring.aop.target.TestActionImpl.view(TestActionImpl.java:15)
at org.spring.aop.main.Test.main(Test.java:17)
请指教