mybatis与spring整合之MapperScannerConfigurer
//实现了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。*/
相关推荐
xiuyangsong 2020-11-16
Nishinoshou 2020-11-09
jimgreatly 2020-09-01
dongxurr 2020-08-18
Dullonjiang 2020-08-15
Dullonjiang 2020-08-11
Dullonjiang 2020-08-09
dongxurr 2020-08-08
yunzhonmghe 2020-08-07
jimgreatly 2020-08-03
Dullonjiang 2020-07-30
jimgreatly 2020-07-27
liqiancao 2020-07-26
xiuyangsong 2020-07-26
dongxurr 2020-07-26
mcvsyy 2020-07-26
helloxusir 2020-07-25
牧场SZShepherd 2020-07-20