2016-01-21 69 views
0

与工厂创建地图豆试图在配置类在@Configuration类

@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=)} 

如何定义一个原型图仅使用注释的bean(无xml)?

回答

0

错误发生是因为Spring试图将Composite注入到您的方法中,但没有与该类相对应的bean。

您可以在SpringConfig类 - see here中添加原型scoped bean。

+0

了解到可以提供“复合”bean。这不是问题。问题是没有必要首先要求一个“综合”bean。地图是空的。 – scorpdaddy