Mybatis框架中找不到mapper包下的文件

176 阅读1分钟

第一段总述

自己最近新建了一个后台管理的java后端项目。用到的后端技术有MySQL、Mybatis、Spring Boot。 主要记录Mybatis框架中mapper文件夹下的文件扫描不到的问题。

第二段介绍

自己第一个功能是整合了Swagger-UI,能够显示controller包中的所有接口。

第三段重点

自己添加了一个商品管理的业务,controller层、interface层、impl层、mapper的interface层、mapper.xml等。 添加业务之前,后台管理工程可以正常启动。添加之后,就一直启动不起来,报一个bean找不到的问题。 尝试了很多种方法。

@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class},scanBasePackages = {"com"})
@EnableAutoConfiguration(exclude = {org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class})
@MapperScan({"com.mapper.mall","com.mapper.facts"})
public class Application {
    public static void main(String[] args) {
        // System.setProperty("spring.devtools.restart.enabled", "false");
        SpringApplication.run(Application.class, args);
    }
}

根本原因是@mapperScan没有扫描到相应的包,导致一个bean找不到。 在启动类中@MapperScan中添加要扫描的包,就可以解决这个问题了。