No qualifying bean of type [] is defined
2017-08-30 17:31
639 查看
No qualifying bean of type [] is defined expected single matching bean but found 2.
使用@autowired时,默认按bean类型装配,当有多个同类型bean时,继续使用名称装配,当名称没有符合的时候,抛出异常。
该异常说明某个装配位置,找到了2个同类型的bean,并且没有与装配位置变量名称一样的bean。
解决方法: 检查@autowired处定义的变量名与需要装载示例名称是否一致。
例如:
HomePageController中使用@autowired注入了一个IHomePageService,
Spring从bean中查找IHomePageService类型的bean装载,
结果发现了两个bean,都是IHomePageService类型.
一个是@service层的实现类HomePageServiceImpl的bean,名字是homePageServiceImpl.
一个是接口IHomePageService的bean,名字是IHomePageService.
因为两个bean类型一直,类型匹配无法确定唯一,@autowired会继续使用名称规则匹配,会使用装配处的变量名homePageService匹配找到的两个bean 的名称,发现还是无法匹配,所以抛出异常。
这个时候把@autowired出的变量名改为homePageServiceImpl就可以匹配到唯一一个bean了,装载成功。
使用@autowired时,默认按bean类型装配,当有多个同类型bean时,继续使用名称装配,当名称没有符合的时候,抛出异常。
该异常说明某个装配位置,找到了2个同类型的bean,并且没有与装配位置变量名称一样的bean。
解决方法: 检查@autowired处定义的变量名与需要装载示例名称是否一致。
例如:
public interface IHomePageService {} @Service @Transactional public class HomePageServiceImpl implements IHomePageService{} @Controller public class HomePageController { @Autowired private IHomePageService homePageService; }
HomePageController中使用@autowired注入了一个IHomePageService,
Spring从bean中查找IHomePageService类型的bean装载,
结果发现了两个bean,都是IHomePageService类型.
一个是@service层的实现类HomePageServiceImpl的bean,名字是homePageServiceImpl.
一个是接口IHomePageService的bean,名字是IHomePageService.
因为两个bean类型一直,类型匹配无法确定唯一,@autowired会继续使用名称规则匹配,会使用装配处的变量名homePageService匹配找到的两个bean 的名称,发现还是无法匹配,所以抛出异常。
这个时候把@autowired出的变量名改为homePageServiceImpl就可以匹配到唯一一个bean了,装载成功。
@Controller public class HomePageController { @Autowired private IHomePageService homePageServiceImpl; }
相关文章推荐
- No qualifying bean of type [org.springframework.scheduling.TaskScheduler] is defined
- spring boot+mybatis 多数据源报错 No qualifying bean of type [javax.sql.DataSource] is defined:
- No qualifying bean of type [com.hz.app.mgmt.system.mgr.SysComBaseSettingMgr] is defined
- spring boot+mybatis 多数据源报错 No qualifying bean of type [javax.sql.DataSource] is defined:
- Spring 定时器 No qualifying bean of type [org.springframework.scheduling.TaskScheduler] is defined
- 关于dao层Bean注入失败报No qualifying bean of type [xxx.xxx.xxx.xxx] is defined错误的问题
- Noqualifying bean of type [org.apache.solr.client.solrj.SolrServer] is defined:expected single match
- springmvc注入类 NoUniqueBeanDefinitionException: No qualifying bean of type [] is defined: expected single错误
- Spring Task Scheduler - No qualifying bean of type [org.springframework.scheduling.TaskScheduler] is defined
- Spring 定时器 No qualifying bean of type [org.springframework.scheduling.TaskScheduler] is defined
- Spring 定时器 No qualifying bean of type [org.springframework.scheduling.TaskScheduler] is defined(转)
- No qualifying bean of type 'com.yubai.el.ELConfig' available
- maven class not found no qualifying bean of type
- No qualifying bean of type [XXX.XXX] found for dependency 解决方法
- No qualifying bean of type [] found for deperidency :
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [cn.itca
- Spring两个数据源配置在容器启动出错,No unique bean of type [org.springframework.jdbc.core.JdbcTemplate] is defined:
- Springboot RedisTemplate 报No qualifying bean of type... 不能按类型装配注入
- No qualifying bean of type found for dependency: expected at least 1 bean which qualifies as autowir
- No qualifying bean of type [com.it.service.DeptService] found for dependency