zoukankan      html  css  js  c++  java
  • Spring AOP基于注解的“零配置”方式---org.springframework.beans.factory.BeanNotOfRequiredTypeException

    具体异常信息如下:

    1 Exception in thread "main" org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'hello' must be of type [com.hyq.chapter08_04_3.HelloImpl], but was actually of type [com.sun.proxy.$Proxy13]
    2     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:376)
    3     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
    4     at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:979)
    5     at com.hyq.chapter08_04_3.AspectTest.main(AspectTest.java:10)

    我在网上搜了一大堆解决方法都不管用,后来发现只要在spring的配置文件bean.xml中的<aop:aspectj-autoproxy/>加上一个属性 proxy-target-class="true",即为:

    <aop:aspectj-autoproxy proxy-target-class="true"/>

    网上查了一下proxy-target-class="true"的相关作用如下:

    • proxy-target-class属性值决定是基于接口的还是基于类的代理被创建。
    • 如果proxy-target-class 属性值被设置为true,那么基于类的代理将起作用(这时需要cglib库)。
    • 如果proxy-target-class属值被设置为false或者这个属性被省略,那么标准的JDK 基于接口的代理将起作用。
  • 相关阅读:
    C语言编程练习51:今年暑假不AC
    C语言编程练习50:素数环
    C语言编程练习49:N皇后问题
    C语言编程练习48:士兵队列训练问题
    C语言编程练习47:看病要排队
    C语言编程练习46:度度熊学队列
    C语言编程练习44:产生冠军
    文言句式
    计算机网络
    计算机组成原理
  • 原文地址:https://www.cnblogs.com/zest/p/5878020.html
Copyright © 2011-2022 走看看