[color=#FF0000]错误消息
exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'zhidingadive' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [Paper.B5] to required type [org.aopalliance.aop.Advice] for property 'advice'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [Paper.B5] to required type [org.aopalliance.aop.Advice] for property 'advice': no matching editors or conversion strategy found
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:480)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at test.test.main(test.java:17)
Caused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [Paper.B5] to required type [org.aopalliance.aop.Advice] for property 'advice'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [Paper.B5] to required type [org.aopalliance.aop.Advice] for property 'advice': no matching editors or conversion strategy found
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:391)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1289)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1250)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
... 14 more
Caused by: java.lang.IllegalArgumentException: Cannot convert value of type [Paper.B5] to required type [org.aopalliance.aop.Advice] for property 'advice': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:231)
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:138)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:386)
... 18 more
[/color]配置文件
<bean id="zhidingadive"
class="org.springframework.aop.support.NameMatchMethodPointcutAdvisor">
 <property name="mappedNames">
 <list>
 <value>getPaperSize</value>
 </list>
  </property>
  <property name="advice">
   <ref bean="b5" />
  </property>
 </bean>大家看看有什么问题,晕。正确后马上结贴。

解决方案 »

  1.   

    <property name="advice"> 
      <ref bean="b5" /> 
      </property> 通知配置有问题
      

  2.   

    是啊,什么问题,thank you
      

  3.   

    配置文件
    <beans>
    <bean id="colorInc" class="Inc.ColorInc"/>
    <bean id="greyInc" class="Inc.GreyInc"/>
    <bean id="a4" class="Paper.A4">
    <property name="size" value="a4"/>
    </bean>
    <bean id="b5" class="Paper.B5">
    <property name="size" value="b5"/>
    </bean>
    <bean id="printer1" class="Printer.Printer">
    <property name="inc" ref="colorInc"/>
    <property name="paper" ref="a4"/>
    </bean>
    <bean id="printer2" class="Printer.Printer">
    <property name="inc" ref="greyInc"/>
    <property name="paper" ref="b5"/>
    </bean>

    <bean id="logAdvice" class="Advice.logAdvice"/>
    <bean id="AfterAdvice" class="Advice.AfterAdvice"/><!--  
    <bean id="zhidingadive"
    class="org.springframework.aop.support.NameMatchMethodPointcutAdvisor">
     <property name="mappedNames">
     <list>
     <value>getPaperSize</value>
     </list>
      </property>
      <property name="advice">
       <ref bean="b5" />
      </property>
     </bean>
    -->
     
    <bean id="proxyBean" class="org.springframework.aop.framework.ProxyFactoryBean">
     <property name="proxyInterfaces">
      <value>Paper.Paper</value>
     </property>
     <property name="interceptorNames">
      <list><value>logAdvice</value></list>
     </property>
     <property name="target" ref="b5"/>
    </bean>
      

  4.   

    <property name="advice">
      <ref bean="b5" /> 
    改成
    <property name="b5">
      <ref bean="b5" />
    试试。 
      

  5.   

    知道什么问题了。谢谢大家!!!是我对spring的配置理解有问题。哈哈送分
      

  6.   

    Cannot convert value of type [Paper.B5] to required type [org.aopalliance.aop.Advice] for property 'advice': no matching editors or conversion strategy found?<bean id="b5" class="Paper.B5"> 
    B5不能是一般的类,你的Paper.B必须5实现org.aopalliance.aop.Advice接口没?
    参考前置通知:
    public class B5implements MethodBeforeAdvice {public void before(Method arg0, Object[] arg1, Object arg2)
        throws Throwable {
       Date date = new Date();
       System.out.println("信息:["+date.toLocaleString()+"] 调用了createPerson()方法。");
    }
    }