【错误分析】Field productMapper in org.spring.springboot.service.impl.ProductServiceImpl required a bean of type 'org.spring.springboot.mapper.ProductMapper' that could not be found.报错,找不到mapper的bean。

1.运行项目,控制台出现以下错误:

***************************
APPLICATION FAILED TO START
应用程序启动失败
***************************

Description:
描述

Field productMapper in org.spring.springboot.service.impl.ProductServiceImpl required a bean of type 'org.spring.springboot.mapper.ProductMapper' that could not be found.
在org.spring.springboot.service.impl中的字段productMapper。ProductServiceImpl需要一个“org.spring.springboot.mapper”类型的bean。没有找到ProductMapper。

Action:
建议
    
Consider defining a bean of type 'org.spring.springboot.mapper.ProductMapper' in your configuration.
    
考虑定义一个“org.spring.springboot.mapper”类型的bean。在您的配置中的ProductMapper。

2.解决办法:当我看到这个错误时,我首先认为我在ProductMapper文件中没有写注解,让ProductServiceImpl调用ProductMapper是找不到bean,但我发现并没有少写注解。后来发现原来是主函数上@MapperScan("org.spring.springboot.mapper")没写明地址。当添加完毕再次运行,就完全没有问题了。

@SpringBootApplication
@MapperScan("org.spring.springboot.mapper")
public class Application {
    public static void main(String[] args) throws Exception {
        SpringApplication.run(Application.class, args);
    }

}

 

3.总结:@MapperScan("mapper路径") 可以扫描接口包 @MapperScan({"mapper路径","mapper路径"}) 扫描多个接口包

posted @ 2020-03-10 15:50  xxxxxo  阅读(1948)  评论(0)    收藏  举报