Skip to content

Commit f7e2020

Browse files
authored
Merge pull request #762 from kazuki43zoo/gh-761
Add a new option whether print warning log if not found mappers that matches conditions on ClassPathMapperScanner
2 parents 7af3a7c + b4b5ed6 commit f7e2020

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/main/java/org/mybatis/spring/mapper/ClassPathMapperScanner.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ public class ClassPathMapperScanner extends ClassPathBeanDefinitionScanner {
6767

6868
private boolean lazyInitialization;
6969

70+
private boolean printWarnLogIfNotFoundMappers = true;
71+
7072
private SqlSessionFactory sqlSessionFactory;
7173

7274
private SqlSessionTemplate sqlSessionTemplate;
@@ -86,6 +88,7 @@ public class ClassPathMapperScanner extends ClassPathBeanDefinitionScanner {
8688
public ClassPathMapperScanner(BeanDefinitionRegistry registry) {
8789
super(registry, false);
8890
setIncludeAnnotationConfig(!NativeDetector.inNativeImage());
91+
setPrintWarnLogIfNotFoundMappers(!NativeDetector.inNativeImage());
8992
}
9093

9194
public void setAddToConfig(boolean addToConfig) {
@@ -111,6 +114,21 @@ public void setLazyInitialization(boolean lazyInitialization) {
111114
this.lazyInitialization = lazyInitialization;
112115
}
113116

117+
/**
118+
* Set whether print warning log if not found mappers that matches conditions.
119+
* <p>
120+
* Default is {@code true}. But {@code false} when running in native image.
121+
* </p>
122+
*
123+
* @param printWarnLogIfNotFoundMappers
124+
* Set the @{code true} to print
125+
*
126+
* @since 3.0.1
127+
*/
128+
public void setPrintWarnLogIfNotFoundMappers(boolean printWarnLogIfNotFoundMappers) {
129+
this.printWarnLogIfNotFoundMappers = printWarnLogIfNotFoundMappers;
130+
}
131+
114132
public void setMarkerInterface(Class<?> markerInterface) {
115133
this.markerInterface = markerInterface;
116134
}
@@ -211,8 +229,10 @@ public Set<BeanDefinitionHolder> doScan(String... basePackages) {
211229
Set<BeanDefinitionHolder> beanDefinitions = super.doScan(basePackages);
212230

213231
if (beanDefinitions.isEmpty()) {
214-
LOGGER.warn(() -> "No MyBatis mapper was found in '" + Arrays.toString(basePackages)
215-
+ "' package. Please check your configuration.");
232+
if (printWarnLogIfNotFoundMappers) {
233+
LOGGER.warn(() -> "No MyBatis mapper was found in '" + Arrays.toString(basePackages)
234+
+ "' package. Please check your configuration.");
235+
}
216236
} else {
217237
processBeanDefinitions(beanDefinitions);
218238
}

0 commit comments

Comments
 (0)