Bootstrap

spring boot应用另一个jar包中的mybatis的mapper文件遇到的坑

被引用的包,因为的mapper.xml不在resources下面,需要把它打进jar包
在pom.xml中加如下代码

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>

    <!-- ......用于扫描 dao 文件下的mapper 文件................. start -->
    <resources>

        <!-- 编译 src/main/java 目录下的 mapper 文件 -->
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
        </resource>
    </resources>
    <!-- ......用于扫描 dao 文件下的mapper 文件................. end -->

</build>

引用的启动类及配置

如果mybatis

mybatis.mapper-locations = classpath*:mapper/*.xml,classpath*:com/letzgo/common/auth/mapper/*.xml
mybatis.type-aliases-package = com.letzgo.common.auth.entity,com.letzgo.common.auth.dto,com.letzgo.common.auth.dao

如果mybatis-plus

mybatis-plus.mapper-locations = classpath*:mapper/*.xml,classpath*:com/letzgo/common/auth/mapper/*.xml
mybatis-plus.type-aliases-package = com.letzgo.common.auth.entity,com.letzgo.common.auth.dto

启动类上加

@ComponentScan({"com.letzgo","org.xx"})

多个用逗号隔开

 

;