zoukankan      html  css  js  c++  java
  • Spring 未初始化声明bean就ref,造成的异常

    今天在做Spring AOP练习的时候,用经典方法。

    创建代理对象的时候直接使用类路径,使用这样的方式

    <bean id="humanProxy" class="org.springframework.aop.framework.ProxyFactoryBean">
      <property name="target" value="test.spring.aop.bean.Human" />
      <property name="interceptorNames" value="sleepHelperAdvisor" />
      <property name="proxyInterfaces" value="test.spring.aop.bean.Sleepable" />
    </bean>

    运行就报错了 nested exception is java.lang.IllegalArgumentException: object is not an instance of declaring class

    后来把 human手动初始化,再关联进来。

    <bean id="human" class="test.spring.aop.bean.Human" />
    <bean id="humanProxy" class="org.springframework.aop.framework.ProxyFactoryBean">
      <property name="target" ref="human" />
      <property name="interceptorNames" value="sleepHelperAdvisor" />
      <property name="proxyInterfaces" value="test.spring.aop.bean.Sleepable" />
    </bean>

    这样就不报错了,说明需要先声明才行。奇怪为什么下面那个接口可以直接用,不用声明。我就试着声明接口之后再ref他。

    结果就报错了 nested exception is org.springframework.beans.BeanInstantiationException:

    Could not instantiate bean class [test.spring.aop.bean.Sleepable]: Specified class is an interface

    不能实例化接口。

  • 相关阅读:
    Linux下升级gcc版本(9.1.0版本)
    Linux/CentOS系统同步网络时间的2种方法详解
    为什么使用promise
    总结js深拷贝和浅拷贝
    js闭包理解
    select框实现多选的功能
    动态添加element-ui组件
    总结鼠标移入移出事件
    echarts提示框太长,导致显示不全 ,撑大div框的问题
    vue项目中管理定时器
  • 原文地址:https://www.cnblogs.com/onlywujun/p/2938193.html
Copyright © 2011-2022 走看看