[英]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.