springboot 整合 mybatis 报错: Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException

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文件中的

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

@Bean

public MapperScannerConfigurermapperScannerConfigurer(){

MapperScannerConfigurer mapperScannerConfigurer =new MapperScannerConfigurer();

    mapperScannerConfigurer.setSqlSessionFactoryBeanName("sqlSessionFactory");

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

    return mapperScannerConfigurer;

}

你可能感兴趣的:(springboot 整合 mybatis 报错: Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException)