请教:Spring @Autowired注解实现了接口的成员变量时失败
场景:
1、类A中有成员变量类B,类B使用@Autowired注解的方式注入A中。
2、类B实现了接口IB.
问题:
启动时报错:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'a':
Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException:
Could not autowire field: com.siqisoft.test.B com.siqisoft.test.A.b;
nested exception is java.lang.IllegalArgumentException:
Can not set com.siqisoft.test.B field com.siqisoft.test.A.b to $Proxy23
疑问:
为什么实现了接口的B不能被注入到A中呢?
类A:
package com.siqisoft.test;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Component;@Componentpublic class A { @Autowired B b;}
package com.siqisoft.test;import org.springframework.stereotype.Component;@Componentpublic class B { public void BMethod(){};}
package com.siqisoft.test;public abstract interface IB { }