Skip to content

Commit 8385595

Browse files
authored
Merge pull request #294 from kazuki43zoo/gh-258_backport-to-1.3.x
Change a method for preventing package based mapper scan
2 parents c75eb3d + 8b8553b commit 8385595

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

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

Lines changed: 18 additions & 18 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.
@@ -188,28 +188,28 @@ public static class AutoConfiguredMapperScannerRegistrar
188188
@Override
189189
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
190190

191-
logger.debug("Searching for mappers annotated with @Mapper");
192-
193-
ClassPathMapperScanner scanner = new ClassPathMapperScanner(registry);
191+
if (!AutoConfigurationPackages.has(this.beanFactory)) {
192+
logger.debug("Could not determine auto-configuration package, automatic mapper scanning disabled.");
193+
return;
194+
}
194195

195-
try {
196-
if (this.resourceLoader != null) {
197-
scanner.setResourceLoader(this.resourceLoader);
198-
}
196+
logger.debug("Searching for mappers annotated with @Mapper");
199197

200-
List<String> packages = AutoConfigurationPackages.get(this.beanFactory);
201-
if (logger.isDebugEnabled()) {
202-
for (String pkg : packages) {
203-
logger.debug("Using auto-configuration base package '{}'", pkg);
204-
}
198+
List<String> packages = AutoConfigurationPackages.get(this.beanFactory);
199+
if (logger.isDebugEnabled()) {
200+
for (String pkg : packages) {
201+
logger.debug("Using auto-configuration base package '{}'", pkg);
205202
}
203+
}
206204

207-
scanner.setAnnotationClass(Mapper.class);
208-
scanner.registerFilters();
209-
scanner.doScan(StringUtils.toStringArray(packages));
210-
} catch (IllegalStateException ex) {
211-
logger.debug("Could not determine auto-configuration package, automatic mapper scanning disabled.", ex);
205+
ClassPathMapperScanner scanner = new ClassPathMapperScanner(registry);
206+
if (this.resourceLoader != null) {
207+
scanner.setResourceLoader(this.resourceLoader);
212208
}
209+
scanner.setAnnotationClass(Mapper.class);
210+
scanner.registerFilters();
211+
scanner.doScan(StringUtils.toStringArray(packages));
212+
213213
}
214214

215215
@Override

0 commit comments

Comments
 (0)