Skip to content

Commit 73d49d6

Browse files
authored
Merge pull request #305 from kazuki43zoo/gh-301-backport
Fix resources scanning bug on SpringBootVFS
2 parents 03e3b62 + 708c6a8 commit 73d49d6

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

mybatis-spring-boot-autoconfigure/src/main/java/org/mybatis/spring/boot/autoconfigure/SpringBootVFS.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2015-2017 the original author or authors.
2+
* Copyright 2015-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,13 +16,11 @@
1616
package org.mybatis.spring.boot.autoconfigure;
1717

1818
import java.io.IOException;
19-
import java.net.URI;
2019
import java.net.URL;
2120
import java.util.ArrayList;
2221
import java.util.List;
2322

2423
import org.apache.ibatis.io.VFS;
25-
2624
import org.springframework.core.io.Resource;
2725
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
2826
import org.springframework.core.io.support.ResourcePatternResolver;
@@ -47,18 +45,20 @@ public boolean isValid() {
4745

4846
@Override
4947
protected List<String> list(URL url, String path) throws IOException {
50-
Resource[] resources = resourceResolver.getResources("classpath*:" + path + "/**/*.class");
48+
String urlString = url.toString();
49+
String baseUrlString = urlString.endsWith("/") ? urlString : urlString.concat("/");
50+
Resource[] resources = resourceResolver.getResources(baseUrlString + "**/*.class");
5151
List<String> resourcePaths = new ArrayList<String>();
5252
for (Resource resource : resources) {
53-
resourcePaths.add(preserveSubpackageName(resource.getURI(), path));
53+
resourcePaths.add(preserveSubpackageName(baseUrlString, resource, path));
5454
}
5555
return resourcePaths;
5656
}
5757

58-
private static String preserveSubpackageName(final URI uri, final String rootPath) {
59-
final String uriStr = uri.toString();
60-
final int start = uriStr.indexOf(rootPath);
61-
return uriStr.substring(start);
58+
private static String preserveSubpackageName(
59+
final String baseUrlString, final Resource resource, final String rootPath) throws IOException {
60+
return rootPath + (rootPath.endsWith("/") ? "" : "/")
61+
+ resource.getURL().toString().substring(baseUrlString.length());
6262
}
6363

6464
}

mybatis-spring-boot-autoconfigure/src/test/java/org/mybatis/spring/boot/autoconfigure/MybatisAutoConfigurationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2015-2018 the original author or authors.
2+
* Copyright 2015-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -280,7 +280,7 @@ public void testMixedWithConfigurationFileAndTypeHandlersPackage() {
280280
EnvironmentTestUtils
281281
.addEnvironment(this.context,
282282
"mybatis.config-location:mybatis-config-settings-only.xml",
283-
"mybatis.type-handlers-package:org.mybatis.spring.boot.autoconfigure.handler");
283+
"mybatis.type-handlers-package:org.mybatis.spring.boot.autoconfigure.handler.");
284284
this.context.register(EmbeddedDataSourceConfiguration.class,
285285
MybatisBootMapperScanAutoConfiguration.class);
286286
this.context.refresh();

0 commit comments

Comments
 (0)