码迷,mamicode.com
首页 > 移动开发 > 详细

如何设置Spring Boot扫描mapper文件

时间:2018-02-22 19:31:08      阅读:9285      评论:0      收藏:0      [点我收藏+]

标签:XML   --   ica   font   figure   public   生成   ati   ota   

一、扫描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);
}
}

 

如何设置Spring Boot扫描mapper文件

标签:XML   --   ica   font   figure   public   生成   ati   ota   

原文地址:https://www.cnblogs.com/nannan0226/p/8459476.html

(1)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!