{channel.title!channel.name} - 楚淮公司周东林

No qualifying bean of type Bean注入失败

主要原因是因为service 类没有加 @Service 注解导致。


报错信息

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'listController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.jschrj.service.JsXfjService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(mappedName=, shareable=true, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER, lookup=)}
 at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:307)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)

 

@Autowired和@Resource的区别

  @Autowired  默认按类型装配   
        依赖对象必须存在,如果要允许null值,可以设置它的required属性为false   @Autowired(required=false)
        也可以使用名称装配,配合@Qualifier注解

  @Resource  默认按名称进行装配,通过name属性进行指定

 

总结:@Autowired自动注解,举个例子吧,一个类,俩个实现类,Autowired就不知道注入哪一个实现类,而Resource有name属性,可以区分。


 


浏览.发表于:2018-11-03 14:13:04