我试图弄清楚如何将此java代码更改为spring
private MyObject myObject = MyObjectFactory.getService();
在我的 Foo.java 类中,我有
@Autowired
private MyObject myObject;
在spring xml中,我有:
<bean id="MyObject" class="path.to.MyObjectFactory" factory-method="getService"></bean>
<bean id="Foo" class="path.to.Foo">
<property name="myObject" ref="MyObject"/>
</bean>
错误是
No matching bean of type [path.to.MyObject] found for dependency:
expected at least 1 bean which qualifies as autowire candidate for this dependency.