为什么在eclipse当中,第一种注入list的方式会报错,而第二种不会?
注入List类型的bean时,由于@Autowired按类型注入的,找不到对应List中String类型的Bean,所以报错,用@Resource替代即可。
我第一种注入list也会报错
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myBean': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void springzhuru.MyBean.setStringList(java.util.List); nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [java.lang.String] found for dependency [collection of java.lang.String]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
可能是你忘记写@Bean了