Skip to content

Commit 4c85df4

Browse files
Mapper is not added to known mapper when it fails to configure.
1 parent 44225b2 commit 4c85df4

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

src/main/java/org/apache/ibatis/binding/MapperRegistry.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,20 @@ public void addMapper(Class<?> type) {
3535
if (knownMappers.contains(type)) {
3636
throw new BindingException("Type " + type + " is already known to the MapperRegistry.");
3737
}
38-
knownMappers.add(type);
39-
// It's important that the type is added before the parser is run
40-
// otherwise the binding may automatically be attempted by the
41-
// mapper parser. If the type is already known, it won't try.
42-
MapperAnnotationBuilder parser = new MapperAnnotationBuilder(config, type);
43-
parser.parse();
38+
boolean loadCompleted = false;
39+
try {
40+
knownMappers.add(type);
41+
// It's important that the type is added before the parser is run
42+
// otherwise the binding may automatically be attempted by the
43+
// mapper parser. If the type is already known, it won't try.
44+
MapperAnnotationBuilder parser = new MapperAnnotationBuilder(config, type);
45+
parser.parse();
46+
loadCompleted = true;
47+
} finally {
48+
if (!loadCompleted) {
49+
knownMappers.remove(type);
50+
}
51+
}
4452
}
4553
}
4654
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ public MapperAnnotationBuilder(Configuration configuration, Class<?> type) {
8585
public void parse() {
8686
String resource = type.toString();
8787
if (!configuration.isResourceLoaded(resource)) {
88-
configuration.addLoadedResource(resource);
8988
loadXmlResource();
89+
configuration.addLoadedResource(resource);
9090
assistant.setCurrentNamespace(type.getName());
9191
parseCache();
9292
parseCacheRef();

src/main/java/org/apache/ibatis/builder/xml/XMLMapperBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public XMLMapperBuilder(Reader reader, Configuration configuration, String resou
4747

4848
public void parse() {
4949
if (!configuration.isResourceLoaded(resource)) {
50-
configuration.addLoadedResource(resource);
5150
configurationElement(parser.evalNode("/mapper"));
51+
configuration.addLoadedResource(resource);
5252
bindMapperForNamespace();
5353
}
5454
}

0 commit comments

Comments
 (0)