Skip to content

Add a new option whether print warning log if not found mappers that matches conditions on ClassPathMapperScanner #762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public class ClassPathMapperScanner extends ClassPathBeanDefinitionScanner {

private boolean lazyInitialization;

private boolean printWarnLogIfNotFoundMappers = true;

private SqlSessionFactory sqlSessionFactory;

private SqlSessionTemplate sqlSessionTemplate;
Expand All @@ -86,6 +88,7 @@ public class ClassPathMapperScanner extends ClassPathBeanDefinitionScanner {
public ClassPathMapperScanner(BeanDefinitionRegistry registry) {
super(registry, false);
setIncludeAnnotationConfig(!NativeDetector.inNativeImage());
setPrintWarnLogIfNotFoundMappers(!NativeDetector.inNativeImage());
}

public void setAddToConfig(boolean addToConfig) {
Expand All @@ -111,6 +114,21 @@ public void setLazyInitialization(boolean lazyInitialization) {
this.lazyInitialization = lazyInitialization;
}

/**
* Set whether print warning log if not found mappers that matches conditions.
* <p>
* Default is {@code true}. But {@code false} when running in native image.
* </p>
*
* @param printWarnLogIfNotFoundMappers
* Set the @{code true} to print
*
* @since 3.0.1
*/
public void setPrintWarnLogIfNotFoundMappers(boolean printWarnLogIfNotFoundMappers) {
this.printWarnLogIfNotFoundMappers = printWarnLogIfNotFoundMappers;
}

public void setMarkerInterface(Class<?> markerInterface) {
this.markerInterface = markerInterface;
}
Expand Down Expand Up @@ -211,8 +229,10 @@ public Set<BeanDefinitionHolder> doScan(String... basePackages) {
Set<BeanDefinitionHolder> beanDefinitions = super.doScan(basePackages);

if (beanDefinitions.isEmpty()) {
LOGGER.warn(() -> "No MyBatis mapper was found in '" + Arrays.toString(basePackages)
+ "' package. Please check your configuration.");
if (printWarnLogIfNotFoundMappers) {
LOGGER.warn(() -> "No MyBatis mapper was found in '" + Arrays.toString(basePackages)
+ "' package. Please check your configuration.");
}
} else {
processBeanDefinitions(beanDefinitions);
}
Expand Down