Skip to content

Commit 2f6716f

Browse files
committed
Use Class#getResourceAsStream(String) to search corresponding XML mapper.
`Class#getResourceAsStream(String)` covers most use cases and it requires the package to be open only to mybatis. `ClassLoader#getResourceAsStream(String)` still is useful if the XML mapper is not in the module but in the classpath. This should fix #1347 .
1 parent 66a5dee commit 2f6716f

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/main/java/org/apache/ibatis/builder/annotation/MapperAnnotationBuilder.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,15 @@ private void loadXmlResource() {
166166
// this flag is set at XMLMapperBuilder#bindMapperForNamespace
167167
if (!configuration.isResourceLoaded("namespace:" + type.getName())) {
168168
String xmlResource = type.getName().replace('.', '/') + ".xml";
169-
InputStream inputStream = null;
170-
try {
171-
inputStream = Resources.getResourceAsStream(type.getClassLoader(), xmlResource);
172-
} catch (IOException e) {
173-
// ignore, resource is not required
169+
// #1347
170+
InputStream inputStream = type.getResourceAsStream("/" + xmlResource);
171+
if (inputStream == null) {
172+
// Search XML mapper that is not in the module but in the classpath.
173+
try {
174+
inputStream = Resources.getResourceAsStream(type.getClassLoader(), xmlResource);
175+
} catch (IOException e2) {
176+
// ignore, resource is not required
177+
}
174178
}
175179
if (inputStream != null) {
176180
XMLMapperBuilder xmlParser = new XMLMapperBuilder(inputStream, assistant.getConfiguration(), xmlResource, configuration.getSqlFragments(), type.getName());

0 commit comments

Comments
 (0)