错误原因:没有引入相应mapper接口,导致spring没有找到依赖

解决方法一:使用注解的方法:

首先在spring配置文件中添加

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.forum" />
        <property name="annotationClass" value="org.springframework.stereotype.Repository" />
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
    </bean>

然后在mapper接口中添加注解

@Transactional
@Repository
public interface RoleMapper

解决方法二:使用xml配置定义mapper的bean

<!— mapper bean -->  
<bean >  
    <property name="mapperInterface" value="com.forum.dao.RoleMapper" />  
    <property name="sqlSessionFactory" ref="sqlSessionFactory" />  
</bean>

不过第二种方法有点繁琐,假如有多个mapper接口的时候,可能要配置多个bean,那就太多了,能把文件撑爆。


 

相关文章:

  • 2022-12-23
  • 2021-06-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-03
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-05
相关资源
相似解决方案