mybatis与spring整合之MapperScannerConfigurer
程序员文章站
2022-03-19 10:59:37
...
//实现了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。*/
上一篇: Html中如何设置超链接文字颜色
下一篇: widgetFactory的创建过程
推荐阅读
-
Mybatis整合spring(适合小白)
-
Mybaits 源码解析 (十)----- 全网最详细,没有之一:Spring-Mybatis框架使用与源码解析
-
Spring实战之XML与JavaConfig的混合配置详解
-
SSM(Spring+SpringMVC+Mybatis)框架整合
-
Spring和Mybatis整合全过程实现(idea实现)适合初学spring和mybatis
-
Spring和Mybatis整合需要导入的依赖
-
spring整合mybatis
-
Spring boot Mybatis整合构建Rest服务(超细版)
-
Mybatis整合spring详细教程(适合小白童鞋)
-
(六) mybatis 源码之 四大对象与插件开发