Springboot 整合 Mybatis-plus时(mapper文件扫描不到)
主类已经配置去扫描mapper包了,但是还会报错:
//主类已经加载配置去扫描mapper包了,但是还会报错
@MapperScan("com.hui.shopping.shopinfo.mapper")
@SpringBootApplication
public class ShoppingApplication {
public static void main(String[] args) {
SpringApplication.run(ShoppingApplication.class, args);
}
}
报错描述:
Property ‘mapperLocations’ was not specified or no matching resources found
问题原因:springboot启动时,src/main/java下只会扫描加载.java文件,而我的mapper.xml也是放在src/main/java目录下的,它扫不到。所以需要指定mapper.xml位置。
1、第一步
在application.properties文件中添加 mapper-locations,内容如下:
mybatis-plus.mapper-locations=classpath:**/mapper/xml/*.xml
2、第二步
需要在pom.xml中指定mapper.xml位置,添加 mapper-locations
<build>
<!--springboot启动时,src/main/java下只会扫描加载.java文件,
而我的mapper.xml是放在src/main/java目录下,这里配置去扫描 xml文件-->
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
</build>