Skip to content

Commit 251e956

Browse files
committed
Output warning log when 'mapperLocations' was specified but matching resources are not found
Fixes gh-12
1 parent 5879993 commit 251e956

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

src/main/java/org/mybatis/spring/SqlSessionFactoryBean.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -518,25 +518,28 @@ protected SqlSessionFactory buildSqlSessionFactory() throws Exception {
518518
this.transactionFactory == null ? new SpringManagedTransactionFactory() : this.transactionFactory,
519519
this.dataSource));
520520

521-
if (!isEmpty(this.mapperLocations)) {
522-
for (Resource mapperLocation : this.mapperLocations) {
523-
if (mapperLocation == null) {
524-
continue;
525-
}
526-
527-
try {
528-
XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(mapperLocation.getInputStream(),
529-
targetConfiguration, mapperLocation.toString(), targetConfiguration.getSqlFragments());
530-
xmlMapperBuilder.parse();
531-
} catch (Exception e) {
532-
throw new NestedIOException("Failed to parse mapping resource: '" + mapperLocation + "'", e);
533-
} finally {
534-
ErrorContext.instance().reset();
521+
if (this.mapperLocations != null) {
522+
if (this.mapperLocations.length == 0) {
523+
LOGGER.warn(() -> "Property 'mapperLocations' was specified but matching resources are not found.");
524+
} else {
525+
for (Resource mapperLocation : this.mapperLocations) {
526+
if (mapperLocation == null) {
527+
continue;
528+
}
529+
try {
530+
XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(mapperLocation.getInputStream(),
531+
targetConfiguration, mapperLocation.toString(), targetConfiguration.getSqlFragments());
532+
xmlMapperBuilder.parse();
533+
} catch (Exception e) {
534+
throw new NestedIOException("Failed to parse mapping resource: '" + mapperLocation + "'", e);
535+
} finally {
536+
ErrorContext.instance().reset();
537+
}
538+
LOGGER.debug(() -> "Parsed mapper file: '" + mapperLocation + "'");
535539
}
536-
LOGGER.debug(() -> "Parsed mapper file: '" + mapperLocation + "'");
537540
}
538541
} else {
539-
LOGGER.debug(() -> "Property 'mapperLocations' was not specified or no matching resources found");
542+
LOGGER.debug(() -> "Property 'mapperLocations' was not specified.");
540543
}
541544

542545
return this.sqlSessionFactoryBuilder.build(targetConfiguration);

0 commit comments

Comments
 (0)