mybatis与spring整合之MapperScannerConfigurer
程序员文章站
2022-03-19 10:52:20
...
//实现了BeanDefinitionRegistryPostProcessor和InitializingBean接口 //所以首先会调用 //判空扫描的包 public void afterPropertiesSet() throws Exception { notNull(this.basePackage, "Property 'basePackage' is required"); } //然后调用 public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException { if (this.processPropertyPlaceHolders) { processPropertyPlaceHolders(); } ClassPathMapperScanner scanner = new ClassPathMapperScanner(registry); scanner.setAddToConfig(this.addToConfig); scanner.setAnnotationClass(this.annotationClass); scanner.setMarkerInterface(this.markerInterface); scanner.setSqlSessionFactory(this.sqlSessionFactory); scanner.setSqlSessionTemplate(this.sqlSessionTemplate); scanner.setSqlSessionFactoryBeanName(this.sqlSessionFactoryBeanName); scanner.setSqlSessionTemplateBeanName(this.sqlSessionTemplateBeanName); scanner.setResourceLoader(this.applicationContext); scanner.setBeanNameGenerator(this.nameGenerator); scanner.registerFilters(); //扫描注册BeanDefinition,需要注意的是这里扫描注册的beanClass是MapperFactoryBean。definition.setBeanClass(MapperFactoryBean.class); scanner.scan(StringUtils.tokenizeToStringArray(this.basePackage, ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS)); } //最后调用 public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) { // left intentionally blank } /** 该类就是扫描mapper所在的package,然后注册到BeanDefinitionRegistry中。交由spring的finishBeanFactoryInitialization(beanFactory); 方法来加载bean。*/
推荐阅读
-
Spring Boot 与 mybatis配置方法
-
Spring学习笔记之RedisTemplate的配置与使用教程
-
spring-mybatis与原生mybatis使用对比分析
-
Spring解密之XML解析与Bean注册示例详解
-
Spring源码解密之自定义标签与解析
-
Spring和MyBatis整合自动生成代码里面text类型遇到的坑
-
Spring Boot整合mybatis并自动生成mapper和实体实例解析
-
mybatis-4 mybatis与spring结合使用及原理解析
-
spring 整合 mybatis 中数据源的几种配置方式(总结篇)
-
Spring Boot+Mybatis的整合过程