Skip to content

Commit

Permalink
修复自动配置lazy-initialization无属性提示,mapper-default-scope配置缺失.
Browse files Browse the repository at this point in the history
  • Loading branch information
nieqiurong committed Feb 21, 2021
1 parent e6fd805 commit 75caa78
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,12 @@
import org.springframework.util.StringUtils;

import javax.sql.DataSource;
import java.beans.PropertyDescriptor;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
Expand Down Expand Up @@ -287,10 +290,17 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, B
builder.addPropertyValue("annotationClass", Mapper.class);
builder.addPropertyValue("basePackage", StringUtils.collectionToCommaDelimitedString(packages));
BeanWrapper beanWrapper = new BeanWrapperImpl(MapperScannerConfigurer.class);
Stream.of(beanWrapper.getPropertyDescriptors())
Set<String> propertyNames = Stream.of(beanWrapper.getPropertyDescriptors()).map(PropertyDescriptor::getName)
.collect(Collectors.toSet());
if (propertyNames.contains("lazyInitialization")) {
// Need to mybatis-spring 2.0.2+
.filter(x -> x.getName().equals("lazyInitialization")).findAny()
.ifPresent(x -> builder.addPropertyValue("lazyInitialization", "${mybatis.lazy-initialization:false}"));
// TODO 兼容了mybatis.lazy-initialization配置
builder.addPropertyValue("lazyInitialization", "${mybatis-plus.lazy-initialization:${mybatis.lazy-initialization:false}}");
}
if (propertyNames.contains("defaultScope")) {
// Need to mybatis-spring 2.0.6+
builder.addPropertyValue("defaultScope", "${mybatis-plus.mapper-default-scope:}");
}
registry.registerBeanDefinition(MapperScannerConfigurer.class.getName(), builder.getBeanDefinition());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@
}
],
"properties": [
{
"defaultValue": false,
"name": "mybatis-plus.lazy-initialization",
"description": "Set whether enable lazy initialization for mapper bean.",
"type": "java.lang.Boolean"
},
{
"defaultValue": "",
"name": "mybatis-plus.mapper-default-scope",
"description": "A default scope for mapper bean that scanned by auto-configure.",
"type": "java.lang.String"
},
{
"sourceType": "com.baomidou.mybatisplus.core.config.GlobalConfig",
"name": "mybatis-plus.global-config.identifier-generator",
Expand Down

0 comments on commit 75caa78

Please sign in to comment.