spring mvc 注入dao失败。

dao层使用mybatis框架,将dao接口和mapper文件整合的方式来操作数据库。
在某个controller中,我使用@Autowired注入某个dao,项目报错了。
No qualifying bean of type [com.xxx.xxxc.dao.UserDao] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
dao层已经用@Repository标注了,为什么还会报错?
我的配置文件如下:
<!-- 扫描文件(自动将dao层注入) -->
<context:component-scan base-package="com.xxx.xxxc.dao"/>

<!-- mybatis文件配置,扫描所有mapper文件 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"
p:dataSource-ref="dataSource" p:configLocation="classpath:mybatis-config.xml" p:mapperLocations="classpath:mapper/*Mapper.xml" />
<!-- configLocation为mybatis配置文件; mapperLocations为所有mapper映射文件,若mybatis配置文件中已经添加mapper映射文件,mapperLocations无需再配,否则报错。
p:mapperLocations="classpath:mapper/*Mapper.xml"
-->
<!-- spring与mybatis整合配置,扫描所有dao -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.xxx.xxxc.dao"/>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
</bean>

<bean id="boardDao" class="wyc.bbs.dao.BoardDao">    
        <property name="sessionFactory" ref="sessionFactory"></property>    
    </bean>    
    <bean id="forumService" class="wyc.bbs.service.ForumService">    
        <property name="boardDao" ref="boardDao"></property>    
    </bean>    
    <bean id="boardController" class="wyc.bbs.web.BoardController">    
        <property name="forumService" ref="forumService"></property>    
    </bean>

BoardDao、ForumService、BoardController有没有set方法或者相应的注解

温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-04-05

配置文件中userdao的id="UserDao" ,这里“”中的文字大小写必须和userController里的变量名保持一致。

SpringMVC属于SpringFrameWork的后续产品,已经融合在SpringWebFlow里面。Spring框架提供了构建Web应用程序的全功能MVC模块。

使用Spring可插入的MVC架构,可以选择是使用内置的SpringWeb框架还可以是Struts这样的Web框架。

本回答被网友采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网