![](/img/trans.png)
[英]Use Spring XML configured bean inside @Configuration Class and Use the bean as factory-bean for another bean
[英]create map bean with a factory in a @Configuration class
尝试在config类中创建具有原型范围的map bean
@Configuration
public class SpringConfig {
public SpringConfig() {
}
@Bean
@Scope("prototype")
public Map<String, Composite> getCompositesMap() {
return new LinkedHashMap<String, Composite>();
}
}
但是春天抱怨
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.eclipse.swt.widgets.Composite] found for dependency [map with value type org.eclipse.swt.widgets.Composite]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER, lookup=)}
如何仅使用注释(不使用xml)定义原型Map Bean?
发生错误是因为Spring尝试将Composite
注入到您的方法中,但是没有与该类相对应的bean。
您可以在SpringConfig
类中添加原型作用域的SpringConfig
请参见此处 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.