Mybatis-Spring之靈異事件
MyBatis-Spring的原始碼裡有這麼一個類,它的程式碼如下
這個類實現了Spring的兩個介面,這兩個介面程式碼如下
靈異事件發生:
在MapperScannerConfigurer類的方法中有logger.warn("No MyBatis mapper was found in '" + MapperScannerConfigurer.this.basePackage
+ "' package. Please check your configuration.");而在類屬性裡卻沒定義logger屬性,程式執行時會丟擲NoSuchFieldError:logger,跑出異常是肯定的,我在想MyBatis團隊是怎麼編譯過這個類還打進Jar的呢?
修改Javac?
修改Spring原始碼?
這似乎都不太可能?你能想到嗎?
public class MapperScannerConfigurer implements BeanFactoryPostProcessor, InitializingBean { private String basePackage; private boolean addToConfig = true; private SqlSessionFactory sqlSessionFactory; private SqlSessionTemplate sqlSessionTemplate; private Class<? extends Annotation> annotationClass; private Class<?> markerInterface; /** * Calls the parent search that will search and register all the candidates. Then the * registered objects are post processed to set them as MapperFactoryBeans */ @[author]Override[/author] protected Set<BeanDefinitionHolder> doScan(String... basePackages) { Set<BeanDefinitionHolder> beanDefinitions = super.doScan(basePackages); if (beanDefinitions.isEmpty()) { logger.warn("No MyBatis mapper was found in '" + MapperScannerConfigurer.this.basePackage + "' package. Please check your configuration."); } else { for (BeanDefinitionHolder holder : beanDefinitions) { GenericBeanDefinition definition = (GenericBeanDefinition) holder.getBeanDefinition(); if (logger.isDebugEnabled()) { logger.debug("Creating MapperFactoryBean with name '" + holder.getBeanName() + "' and '" + definition.getBeanClassName() + "' mapperInterface"); } // the mapper interface is the original class of the bean // but, the actual class of the bean is MapperFactoryBean definition.getPropertyValues().add("mapperInterface", definition.getBeanClassName()); definition.setBeanClass(MapperFactoryBean.class); definition.getPropertyValues().add("addToConfig", MapperScannerConfigurer.this.addToConfig); if (MapperScannerConfigurer.this.sqlSessionFactory != null) { definition.getPropertyValues().add("sqlSessionFactory", MapperScannerConfigurer.this.sqlSessionFactory); } if (MapperScannerConfigurer.this.sqlSessionTemplate != null) { definition.getPropertyValues().add("sqlSessionTemplate", MapperScannerConfigurer.this.sqlSessionTemplate); } } } return beanDefinitions; } @[author]Override[/author] protected boolean isCandidateComponent(AnnotatedBeanDefinition beanDefinition) { return (beanDefinition.getMetadata().isInterface() && beanDefinition.getMetadata().isIndependent()); } @[author]Override[/author] protected boolean checkCandidate(String beanName, BeanDefinition beanDefinition) throws IllegalStateException { if (super.checkCandidate(beanName, beanDefinition)) { return true; } else { logger.warn("Skipping MapperFactoryBean with name '" + beanName + "' and '" + beanDefinition.getBeanClassName() + "' mapperInterface" + ". Bean already defined with the same name!"); return false; } } } } <p class="indent"> |
這個類實現了Spring的兩個介面,這兩個介面程式碼如下
public interface InitializingBean { /** * Invoked by a BeanFactory after it has set all bean properties supplied * (and satisfied BeanFactoryAware and ApplicationContextAware). * <p>This method allows the bean instance to perform initialization only * possible when all bean properties have been set and to throw an * exception in the event of misconfiguration. * @throws Exception in the event of misconfiguration (such * as failure to set an essential property) or if initialization fails. */ void afterPropertiesSet() throws Exception; } <p class="indent"> |
public interface BeanFactoryPostProcessor { /** * Modify the application context's internal bean factory after its standard * initialization. All bean definitions will have been loaded, but no beans * will have been instantiated yet. This allows for overriding or adding * properties even to eager-initializing beans. * @param beanFactory the bean factory used by the application context * @throws org.springframework.beans.BeansException in case of errors */ void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException; } <p class="indent"> |
靈異事件發生:
在MapperScannerConfigurer類的方法中有logger.warn("No MyBatis mapper was found in '" + MapperScannerConfigurer.this.basePackage
+ "' package. Please check your configuration.");而在類屬性裡卻沒定義logger屬性,程式執行時會丟擲NoSuchFieldError:logger,跑出異常是肯定的,我在想MyBatis團隊是怎麼編譯過這個類還打進Jar的呢?
修改Javac?
修改Spring原始碼?
這似乎都不太可能?你能想到嗎?
[該貼被oojdon於2011-04-18 23:40修改過]
相關文章
- 當“靈異”事件發生時事件
- SQL優化中索引列使用函式之靈異事件SQL優化索引函式事件
- 大學多宗持續靈異事件事件
- SQL最佳化中索引列使用函式之靈異事件SQL索引函式事件
- mybatis快取,從一個“靈異”事件說起MyBatis快取事件
- 記一次開發中的靈異事件事件
- 靈異事件的始作俑者:Reset資料包(後續)(1)事件
- javascript 靈異現象之 if else 先後執行JavaScript
- 用MsmqBinding投送message出現的一個靈異事件 【第二篇】MQ事件
- 詭異!React stopPropagation失靈React
- mybatis-spring啟動到使用MyBatisSpring
- BW 異常事件記錄事件
- mybatis-spring官網學習心得MyBatisSpring
- mybatis-spring sql執行過程分析MyBatisSpringSQL
- javaScript事件(五)事件型別之滑鼠事件JavaScript事件型別
- tomcat伺服器奇異事件Tomcat伺服器事件
- mysql慢查詢的奇異事件MySql事件
- (interbase之九)intebase的儲存過程、觸發器以及事件、異常 (轉)儲存過程觸發器事件
- 開發者眼中的那些都市傳說與靈異事件 —— 《零》×《真女神轉生 5》萬聖節對談事件
- [異常等待事件latch undo global data]分析事件
- java之異常Java
- 事件分發之View事件處理事件View
- 事件消費者之 Projector - 事件溯源事件Project
- 事件消費者之 Reactor - 事件溯源事件React
- delphi OnMouseLeave 事件不靈敏及解決之道事件
- 6大特色玩法御靈遠征《異界深淵:大靈王》今日震撼首發
- 事件消費者之 Saga - 事件溯源事件
- 一個執行緒罷工的詭異事件執行緒事件
- [異常等待事件rdbms ipc reply]-分析說明事件
- Javascript事件模型系列(三)jQuery中的事件監聽方式及異同點JavaScript事件模型jQuery
- [靈性程式設計]函式委託,自動事件程式設計函式事件
- java之JAVA異常Java
- hibernate異常之--count查詢異常
- 精盡MyBatis原始碼分析 - MyBatis-Spring 原始碼分析MyBatis原始碼Spring
- 圖靈改版之我的想法圖靈
- vue之監聽事件Vue事件
- 【TUNE_ORACLE】等待事件之等待事件類別Oracle事件
- 記一次靈異般的 Bug 除錯經歷除錯