No qualifying bean of type [com.zc.service.IFancyService] found for dependency

时间:2022-09-11 15:07:43

在使用spring mvc,mybatis时报以下错误:

No qualifying bean of type [com.zc.service.IFancyService] found for dependency

这个原因是没有配置spring对包进行扫描,找不到注解;

解决方法:

1、加上扫描配置

<!--启动spring的组件自动扫描机制-->
    <context:component-scan base-package="com.zc.controller" />
    <context:component-scan base-package="com.zc.dao"/> 
     <context:component-scan base-package="com.zc.service.impl"/>
问题解决。

2、<!-- 数据映射器类  mapper bean -->

<bean id="RecentlyMapper" class="org.mybatis.spring.mapper.MapperFactoryBean" >
        <property name="sqlSessionFactory" ref="SqlSessionFactory" />
        <!-- 注意指定的映射器类必须是一个接口,而不是具体的实现类  -->
        <property name="mapperInterface" value="com.zc.product.dao.IRecentlyMapper" />
    </bean>