+ * This is an alternative to specifying "<sqlmapper>" entries in an MyBatis config file. This property being
+ * based on Spring's resource abstraction also allows for specifying resource patterns here: e.g.
+ * "classpath*:sqlmap/*-mapper.xml".
+ *
+ * @param mapperLocations
+ * location of MyBatis mapper files
+ *
+ * @see #setMapperLocations(Resource...)
+ *
+ * @since 3.0.2
+ */
+ public void addMapperLocations(Resource... mapperLocations) {
+ setMapperLocations(appendArrays(this.mapperLocations, mapperLocations, Resource[]::new));
+ }
+
+ /**
+ * Add type handlers.
+ *
+ * @param typeHandlers
+ * Type handler list
+ *
+ * @since 3.0.2
+ */
+ public void addTypeHandlers(TypeHandler>... typeHandlers) {
+ setTypeHandlers(appendArrays(this.typeHandlers, typeHandlers, TypeHandler[]::new));
+ }
+
+ /**
+ * Add scripting language drivers.
+ *
+ * @param scriptingLanguageDrivers
+ * scripting language drivers
+ *
+ * @since 3.0.2
+ */
+ public void addScriptingLanguageDrivers(LanguageDriver... scriptingLanguageDrivers) {
+ setScriptingLanguageDrivers(
+ appendArrays(this.scriptingLanguageDrivers, scriptingLanguageDrivers, LanguageDriver[]::new));
+ }
+
+ /**
+ * Add Mybatis plugins.
+ *
+ * @param plugins
+ * list of plugins
+ *
+ * @since 3.0.2
+ */
+ public void addPlugins(Interceptor... plugins) {
+ setPlugins(appendArrays(this.plugins, plugins, Interceptor[]::new));
+ }
+
+ /**
+ * Add type aliases.
+ *
+ * @param typeAliases
+ * Type aliases list
+ *
+ * @since 3.0.2
*/
+ public void addTypeAliases(Class>... typeAliases) {
+ setTypeAliases(appendArrays(this.typeAliases, typeAliases, Class[]::new));
+ }
+
+ private
+ * The default is {@literal true}. This means that a property placeholder processing execute.
+ *
+ * @since 3.0.3
+ *
+ * @return a flag that whether execute a property placeholder processing or not
+ */
+ boolean processPropertyPlaceHolders() default true;
+
+ /**
+ * Specifies which types are not eligible for mapper scanning.
+ *
+ * @since 3.0.4
+ *
+ * @return array of customized mapper excludeFilter
+ */
+ ComponentScan.Filter[] excludeFilters() default {};
+
}
diff --git a/src/main/java/org/mybatis/spring/annotation/MapperScannerRegistrar.java b/src/main/java/org/mybatis/spring/annotation/MapperScannerRegistrar.java
index cde801d739..81ecd2f1ff 100644
--- a/src/main/java/org/mybatis/spring/annotation/MapperScannerRegistrar.java
+++ b/src/main/java/org/mybatis/spring/annotation/MapperScannerRegistrar.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2010-2022 the original author or authors.
+ * Copyright 2010-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,7 +18,9 @@
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.stream.Collectors;
import org.mybatis.spring.mapper.ClassPathMapperScanner;
@@ -31,10 +33,15 @@
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.context.ResourceLoaderAware;
+import org.springframework.context.annotation.FilterType;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.type.AnnotationMetadata;
+import org.springframework.core.type.filter.AnnotationTypeFilter;
+import org.springframework.core.type.filter.AssignableTypeFilter;
+import org.springframework.core.type.filter.TypeFilter;
+import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
@@ -54,23 +61,17 @@
*/
public class MapperScannerRegistrar implements ImportBeanDefinitionRegistrar, ResourceLoaderAware {
- /**
- * {@inheritDoc}
- *
- * @deprecated Since 2.0.2, this method not used never.
- */
+ // Note: Do not move resourceLoader via cleanup
+ private ResourceLoader resourceLoader;
+
@Override
- @Deprecated
public void setResourceLoader(ResourceLoader resourceLoader) {
- // NOP
+ this.resourceLoader = resourceLoader;
}
- /**
- * {@inheritDoc}
- */
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
- AnnotationAttributes mapperScanAttrs = AnnotationAttributes
+ var mapperScanAttrs = AnnotationAttributes
.fromMap(importingClassMetadata.getAnnotationAttributes(MapperScan.class.getName()));
if (mapperScanAttrs != null) {
registerBeanDefinitions(importingClassMetadata, mapperScanAttrs, registry,
@@ -81,8 +82,8 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, B
void registerBeanDefinitions(AnnotationMetadata annoMeta, AnnotationAttributes annoAttrs,
BeanDefinitionRegistry registry, String beanName) {
- BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(MapperScannerConfigurer.class);
- builder.addPropertyValue("processPropertyPlaceHolders", true);
+ var builder = BeanDefinitionBuilder.genericBeanDefinition(MapperScannerConfigurer.class);
+ builder.addPropertyValue("processPropertyPlaceHolders", annoAttrs.getBoolean("processPropertyPlaceHolders"));
Class extends Annotation> annotationClass = annoAttrs.getClass("annotationClass");
if (!Annotation.class.equals(annotationClass)) {
@@ -104,20 +105,18 @@ void registerBeanDefinitions(AnnotationMetadata annoMeta, AnnotationAttributes a
builder.addPropertyValue("mapperFactoryBeanClass", mapperFactoryBeanClass);
}
- String sqlSessionTemplateRef = annoAttrs.getString("sqlSessionTemplateRef");
+ var sqlSessionTemplateRef = annoAttrs.getString("sqlSessionTemplateRef");
if (StringUtils.hasText(sqlSessionTemplateRef)) {
builder.addPropertyValue("sqlSessionTemplateBeanName", annoAttrs.getString("sqlSessionTemplateRef"));
}
- String sqlSessionFactoryRef = annoAttrs.getString("sqlSessionFactoryRef");
+ var sqlSessionFactoryRef = annoAttrs.getString("sqlSessionFactoryRef");
if (StringUtils.hasText(sqlSessionFactoryRef)) {
builder.addPropertyValue("sqlSessionFactoryBeanName", annoAttrs.getString("sqlSessionFactoryRef"));
}
- List