避免客户端代码直接引用目标Bean

在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)

 

请指教

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值