如何设置Spring Boot扫描mapper文件

一、扫描mapper接口文件:

1、推荐:

在Application.java启动文件中,加注解:

@MapperScan("com.xxx.mapper")

2、

@Mapper
因为我的mapper是一个模块,portal一个模块.
mapper在com.xxx.mapper下
portal的groupid是com.xxx,这样可以@Mapper直接扫描到.
但是
mybatis-generator生成的mapper并没有@mapper,即使折腾出来了,虽然对运行效率不会有什么影响,启动就会变慢,浪费时间,所以不推荐。

 二、扫描mapper.xml文件

1、application.properties配置:mybatis.mapper-locations: classpath:mappers/*.xml

2、

<!-- 配置扫描包,加载mapper代理对象 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.xxx.mapper"></property>
</bean>

 

@SpringBootApplication
@ImportResource(locations = "classpath:spring-dao.xml")
public class PortalApplication {

 

public static void main(String[] args) {
SpringApplication.run(PortalApplication.class, args);
}
}

 

文章来自:https://www.cnblogs.com/nannan0226/p/8459476.html
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3