繁体   English   中英

在@Configuration类中使用工厂创建映射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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM