在移植一個項目的過程中,偶然出現(xiàn)了一個問題:
Caused by: java.lang.NumberFormatException: For input string: "${db.maxPoolSize}"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:481)
at java.lang.Integer.valueOf(Integer.java:582)
at org.springframework.util.NumberUtils.parseNumber(NumberUtils.java:193)
at org.springframework.beans.propertyeditors.CustomNumberEditor.setAsText(CustomNumberEditor.java:113)
at org.springframework.beans.TypeConverterDelegate.doConvertTextValue(TypeConverterDelegate.java:450)
at org.springframework.beans.TypeConverterDelegate.doConvertValue(TypeConverterDelegate.java:423)
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:195)
at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:461)
... 64 more
該異常對應的配置是:
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${db.driverClass}" />
<property name="jdbcUrl" value="${db.jdbcUrl}" />
<property name="user" value="${db.user}" />
<property name="password" value="${db.password}" />
<property name="maxPoolSize" value="${db.maxPoolSize}" />
<property name="minPoolSize" value="${db.minPoolSize}" />
<property name="initialPoolSize" value="${db.initialPoolSize}" />
<property name="maxIdleTime" value="${db.maxIdleTime}" />
<property name="maxStatements" value="${db.maxStatements}" />
<property name="acquireIncrement" value="${db.acquireIncrement}" />
</bean>
但是項目的早期并沒有出現(xiàn)這種情況,百思不得其解,google搜索發(fā)現(xiàn)這個問題以前是MapperScannerConfigurer的處理方式有問題,大多人換用sqlSessionFactoryBeanName配置后問題都解決了,而我的項目中一直出現(xiàn)這個惱人的問題。
后來懷疑是第三方封裝spring框架的原因,于是打開代碼調(diào)試,忽然發(fā)現(xiàn)報了一個異常但是異常被靜默消化掉了,異常語句是:


靜默消化的異常信息:ConflictingBeanDefinitionException : Annotation-specified bean name 'adMapper' for bean class [com.vivo.ads.persist.mapper.ocpc.AdMapper] conflicts with existing, non-compatible bean definition of same name and class [com.vivo.ads.security.dal.mapper.AdMapper]
這個異常本來應當拋出以停止初始化的,但是第三方框架將它消化掉了,導致錯誤延后出現(xiàn),繼而出現(xiàn)了難以查找原因的bug。
經(jīng)查原來是一個新建的Mapper和一個引入的Mapper重名(限定名完全相同)導致的,之后改個名字就OK了。
不得不說,第三方框架還是做得很粗糙。有待改進,有時候調(diào)試源代碼也是必要的,當然,熟知Spring原理才是王道。
第三方框架為什么在Spring認為這個任務不能完成之后,還要繼續(xù)往前執(zhí)行呢?腦子真是不好使,有時候拋出異常對大家都有好處,即使這個異常是未受檢的。