当前位置: 代码迷 >> 综合 >> mybatis.mapper-locations 包含jar包文件配置多个mapper路径
  详细解决方案

mybatis.mapper-locations 包含jar包文件配置多个mapper路径

热度:33   发布时间:2024-01-29 08:05:57.0

在一次的公司项目微服务化的时候,遇到一个问题:项目A中带有mapper.xml文件,项目B中也有其他的mapper.xml。这个时候项目A在某些场景的情况下需要把B打成JAR包引入到A,那么这个时候两个项目的包路径不一致,,mapper.xml的路径也不一样,这个时候就需要引入多个路径。

项目A:mapper.xml 路径在 resources/mybatis/mapper/push 下面

mybatis-plus:mapper-locations: classpath:mybatis/*.xml

项目B,mapper.xml 路径再 resources/mappers/下面

mybatis-plus:mapper-locations: classpath*:/mapper/*.xml

步骤:

1、项目A引用了项目B,把项目B的jar包加入到pom文件中了

2、那么项目A的application.properties配置文件中配置mapper.xml路径如下:

mybatis.mapper-locations=classpath:mybatis/mapper/*.xml,classpath*:/mappers/*.xml
注意点:在classpath后面的 * 必不可少,缺少型号的话后面的通配符不起作用

  相关解决方案