if (this.mapperLocations != null) {
        if (this.mapperLocations.length == 0) {
            LOGGER.warn(() -> "Property 'mapperLocations' was specified but matching resources are not found.");
        } else {
            for (Resource mapperLocation : this.mapperLocations) {
                if (mapperLocation == null) {
                    continue;
                }
                try {
                    XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(mapperLocation.getInputStream(),
                        targetConfiguration, mapperLocation.toString(), targetConfiguration.getSqlFragments());
                    xmlMapperBuilder.parse();
                } catch (Exception e) {
                    throw new IOException("Failed to parse mapping resource: '" + mapperLocation + "'", e);
                } finally {
                    ErrorContext.instance().reset();
                }
                LOGGER.debug(() -> "Parsed mapper file: '" + mapperLocation + "'");
            }
        }
    } else {
        LOGGER.debug(() -> "Property 'mapperLocations' was not specified.");
    }

Comment From: nieqiurong

具体耗时多久.

Comment From: sk142857

具体耗时多久.

我的一个项目,大概几十个mapper文件,加载用了100秒,确实很慢!暂时,还找到解决办法。

2023-08-28 12:27:21.551 | DEBUG [] main | sun.net.www.protocol.http.HttpURLConnection | sun.net.www.MessageHeader@77d245ec22 pairs: {null: HTTP/1.1 200 OK}{Connection: keep-alive}{Content-Length: 7458}{Server: GitHub.com}{Content-Type: application/xml-dtd}{Last-Modified: Wed, 07 Sep 2022 23:28:43 GMT}{Access-Control-Allow-Origin: *}{ETag: "6319292b-1d22"}{expires: Mon, 14 Aug 2023 21:56:53 GMT}{Cache-Control: max-age=600}{x-proxy-cache: HIT}{X-GitHub-Request-Id: 96C4:3E0C:6410D:6C96F:64DAA174}{Accept-Ranges: bytes}{Date: Mon, 28 Aug 2023 04:27:21 GMT}{Via: 1.1 varnish}{Age: 47}{X-Served-By: cache-tyo11946-TYO}{X-Cache: HIT}{X-Cache-Hits: 8}{X-Timer: S1693196842.562735,VS0,VE0}{Vary: Accept-Encoding}{X-Fastly-Request-ID: d125da13abbd92860e4d1f5faf1a937ea7ef698e}
2023-08-28 12:27:21.674 | DEBUG [] main | com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean | Parsed mapper file: 'file [/mapper/DemoMapper.xml]'
2023-08-28 12:27:21.675 | DEBUG [] main | sun.net.www.protocol.http.HttpURLConnection | sun.net.www.MessageHeader@1697c6bf5 pairs: {GET /dtd/mybatis-3-mapper.dtd HTTP/1.1: null}{User-Agent: Java/17.0.7}{Host: mybatis.org}{Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2}{Connection: keep-alive}
2023-08-28 12:27:21.772 | DEBUG [] main | sun.net.www.protocol.http.HttpURLConnection | sun.net.www.MessageHeader@5c0796cc22 pairs: {null: HTTP/1.1 200 OK}{Connection: keep-alive}{Content-Length: 7458}{Server: GitHub.com}{Content-Type: application/xml-dtd}{Last-Modified: Wed, 07 Sep 2022 23:28:43 GMT}{Access-Control-Allow-Origin: *}{ETag: "6319292b-1d22"}{expires: Mon, 14 Aug 2023 21:56:53 GMT}{Cache-Control: max-age=600}{x-proxy-cache: HIT}{X-GitHub-Request-Id: 96C4:3E0C:6410D:6C96F:64DAA174}{Accept-Ranges: bytes}{Date: Mon, 28 Aug 2023 04:27:21 GMT}{Via: 1.1 varnish}{Age: 48}{X-Served-By: cache-tyo11946-TYO}{X-Cache: HIT}{X-Cache-Hits: 9}{X-Timer: S1693196842.783687,VS0,VE0}{Vary: Accept-Encoding}{X-Fastly-Request-ID: e45ce1004d986bfe2a2cf97e7e2ed632faa5321f}
2023-08-28 12:27:21.790 | DEBUG [] main | com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean | Parsed mapper file: 'file [/mapper/DemoMapper.xml]'
2023-08-28 12:27:21.791 | DEBUG [] main | sun.net.www.protocol.http.HttpURLConnection | sun.net.www.MessageHeader@400b84be5 pairs: {GET /dtd/mybatis-3-mapper.dtd HTTP/1.1: null}{User-Agent: Java/17.0.7}{Host: mybatis.org}{Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2}{Connection: keep-alive}
2023-08-28 12:27:22.006 | DEBUG [] main | sun.net.www.protocol.http.HttpURLConnection | sun.net.www.MessageHeader@934743622 pairs: {null: HTTP/1.1 200 OK}{Connection: keep-alive}{Content-Length: 7458}{Server: GitHub.com}{Content-Type: application/xml-dtd}{Last-Modified: Wed, 07 Sep 2022 23:28:43 GMT}{Access-Control-Allow-Origin: *}{ETag: "6319292b-1d22"}{expires: Mon, 14 Aug 2023 21:56:53 GMT}{Cache-Control: max-age=600}{x-proxy-cache: HIT}{X-GitHub-Request-Id: 96C4:3E0C:6410D:6C96F:64DAA174}{Accept-Ranges: bytes}{Date: Mon, 28 Aug 2023 04:27:21 GMT}{Via: 1.1 varnish}{Age: 48}{X-Served-By: cache-tyo11946-TYO}{X-Cache: HIT}{X-Cache-Hits: 10}{X-Timer: S1693196842.901197,VS0,VE0}{Vary: Accept-Encoding}{X-Fastly-Request-ID: 9ca362b6be2a34905ec9b5b9106f9f88886e8a06}
2023-08-28 12:27:22.016 | DEBUG [] main | com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean | Parsed mapper file: 'file [/mapper/UserMapper.xml]'
2023-08-28 12:27:22.017 | DEBUG [] main | sun.net.www.protocol.http.HttpURLConnection | sun.net.www.MessageHeader@66e0c2085 pairs: {GET /dtd/mybatis-3-mapper.dtd HTTP/1.1: null}{User-Agent: Java/17.0.7}{Host: mybatis.org}{Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2}{Connection: keep-alive}
2023-08-28 12:27:22.114 | DEBUG [] main | sun.net.www.protocol.http.HttpURLConnection | sun.net.www.MessageHeader@32b1029722 pairs: {null: HTTP/1.1 200 OK}{Connection: keep-alive}{Content-Length: 7458}{Server: GitHub.com}{Content-Type: application/xml-dtd}{Last-Modified: Wed, 07 Sep 2022 23:28:43 GMT}{Access-Control-Allow-Origin: *}{ETag: "6319292b-1d22"}{expires: Mon, 14 Aug 2023 21:56:53 GMT}{Cache-Control: max-age=600}{x-proxy-cache: HIT}{X-GitHub-Request-Id: 96C4:3E0C:6410D:6C96F:64DAA174}{Accept-Ranges: bytes}{Date: Mon, 28 Aug 2023 04:27:22 GMT}{Via: 1.1 varnish}{Age: 48}{X-Served-By: cache-tyo11946-TYO}{X-Cache: HIT}{X-Cache-Hits: 11}{X-Timer: S1693196842.126134,VS0,VE0}{Vary: Accept-Encoding}{X-Fastly-Request-ID: 83ba99d1c811d5f7b2c5eb270803d35bcd2cff0c}
2023-0

Comment From: Croyson

具体耗时多久.

100多个xml文件,耗时 200多秒,后面我把空的 .xml 文件都删除了,快了不少

Comment From: sk142857

具体耗时多久.

100多个xml文件,耗时 200多秒,后面我把空的 .xml 文件都删除了,快了不少

调试发现,根据官方例子,需要设置javax.xml.accessExternalDTD=all,然后应用加载每一个mapper文件,都会去mybatis.org网站下载dtd文件,导致加载速度变慢。

Comment From: nieqiurong

具体耗时多久.

100多个xml文件,耗时 200多秒,后面我把空的 .xml 文件都删除了,快了不少

普通项目,还是native情况下.

Comment From: nieqiurong

具体耗时多久.

100多个xml文件,耗时 200多秒,后面我把空的 .xml 文件都删除了,快了不少

调试发现,根据官方例子,需要设置javax.xml.accessExternalDTD=all,然后应用加载每一个mapper文件,都会去mybatis.org网站下载dtd文件,导致加载速度变慢。

native情况统一在置顶下讨论.

Comment From: sk142857

不是 mybatis-plus 的问题,已经修复了,解决方案:https://github.com/mybatis/spring-boot-starter/issues/852