美文网首页
springboot 整合 mybatis 报错: Caused

springboot 整合 mybatis 报错: Caused

作者: 转角大大 | 来源:发表于2018-09-17 16:51 被阅读0次

    Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.****.mybatis.springboot.mapper.UserMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

    产生问题的原因在于,没有配置mapper层的扫描,解决办法如下:

    1.springboot启动类,添加mapper层的扫描注解@MapperScan({"com.lookthings.client.dao"})

    这样配置相当于spring xml文件中的<mapper namespace="com.***.mybatis.springboot.mapper.UserMapper" >

    2.扫描配置:配置类中添加以下扫描配置

    @Bean

    public MapperScannerConfigurermapperScannerConfigurer(){

    MapperScannerConfigurer mapperScannerConfigurer =new MapperScannerConfigurer();

        mapperScannerConfigurer.setSqlSessionFactoryBeanName("sqlSessionFactory");

        mapperScannerConfigurer.setBasePackage("com.lookthings.client.dao");

        return mapperScannerConfigurer;

    }

    相关文章

      网友评论

          本文标题:springboot 整合 mybatis 报错: Caused

          本文链接:https://www.haomeiwen.com/subject/ygdrnftx.html