0

Trying to create a map bean with prototype scope in config class

@Configuration
public class SpringConfig {

   public SpringConfig() {
   }


   @Bean
   @Scope("prototype")
   public Map<String, Composite> getCompositesMap() {
      return new LinkedHashMap<String, Composite>();
   }
}

But spring complains

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

How does one define a prototype map bean using annotations only (no xml)?

scorpdaddy
  • 303
  • 3
  • 14

1 Answers1

0

The error is occurring because Spring is trying to inject Composite into your method, but there is no such bean that corresponds to that class.

You can add a prototype scoped bean inside your SpringConfig class - see here.

Community
  • 1
  • 1
erik-sn
  • 2,590
  • 1
  • 20
  • 37
  • Understood that one can provide a "Composite" bean. That is not the issue. The issue is that there is no need to ask for a "Composite" bean in the first place. The Map is empty. – scorpdaddy Jan 22 '16 at 17:26