|
@@ -8,17 +8,33 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
8
|
8
|
import org.springframework.beans.factory.support.BeanNameGenerator;
|
9
|
9
|
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
|
10
|
10
|
import org.springframework.core.type.AnnotationMetadata;
|
|
11
|
+import org.springframework.core.type.classreading.MetadataReader;
|
|
12
|
+import org.springframework.core.type.classreading.MetadataReaderFactory;
|
|
13
|
+import org.springframework.core.type.filter.TypeFilter;
|
|
14
|
+
|
|
15
|
+import java.io.IOException;
|
|
16
|
+import java.util.Map;
|
11
|
17
|
|
12
|
18
|
public class MyImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {
|
13
|
19
|
@Override
|
14
|
20
|
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry, BeanNameGenerator importBeanNameGenerator) {
|
15
|
|
- AbstractBeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition().getBeanDefinition();
|
16
|
|
- beanDefinition.setBeanClass(MybatisFactoryBean.class);
|
17
|
|
- beanDefinition.getConstructorArgumentValues().addGenericArgumentValue(UserMapper.class);
|
18
|
|
- registry.registerBeanDefinition("userMapper",beanDefinition);
|
19
|
|
- AbstractBeanDefinition beanDefinition2 = BeanDefinitionBuilder.genericBeanDefinition().getBeanDefinition();
|
20
|
|
- beanDefinition2.setBeanClass(MybatisFactoryBean.class);
|
21
|
|
- beanDefinition2.getConstructorArgumentValues().addGenericArgumentValue(OrderMapper.class);
|
22
|
|
- registry.registerBeanDefinition("orderMapper",beanDefinition2);
|
|
21
|
+ Map<String, Object> annotationAttributes = importingClassMetadata.getAnnotationAttributes(MyMapperScan.class.getName());
|
|
22
|
+ String path = ((String) annotationAttributes.get("value"));
|
|
23
|
+ MapperScanner mapperScanner = new MapperScanner(registry);
|
|
24
|
+ mapperScanner.addIncludeFilter(new TypeFilter() {
|
|
25
|
+ @Override
|
|
26
|
+ public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {
|
|
27
|
+ return true;
|
|
28
|
+ }
|
|
29
|
+ });
|
|
30
|
+ mapperScanner.scan(path);
|
|
31
|
+// AbstractBeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition().getBeanDefinition();
|
|
32
|
+// beanDefinition.setBeanClass(MybatisFactoryBean.class);
|
|
33
|
+// beanDefinition.getConstructorArgumentValues().addGenericArgumentValue(UserMapper.class);
|
|
34
|
+// registry.registerBeanDefinition("userMapper",beanDefinition);
|
|
35
|
+// AbstractBeanDefinition beanDefinition2 = BeanDefinitionBuilder.genericBeanDefinition().getBeanDefinition();
|
|
36
|
+// beanDefinition2.setBeanClass(MybatisFactoryBean.class);
|
|
37
|
+// beanDefinition2.getConstructorArgumentValues().addGenericArgumentValue(OrderMapper.class);
|
|
38
|
+// registry.registerBeanDefinition("orderMapper",beanDefinition2);
|
23
|
39
|
}
|
24
|
40
|
}
|