1. 程式人生 > >關於spring的applicationContext.xml配置文件的ref和value之自我想法

關於spring的applicationContext.xml配置文件的ref和value之自我想法

定時 框架 ots 類型轉換 job ica ont spring配置 str

今天在做SSH的一個項目的時候,因為需要定時操作,所以就再sping裏面加入了一個quartz的小定時框架,結果在運行時候,發生了一個小bug.

Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type ‘java.lang.String‘ to required type ‘org.quartz.spi.JobFactory‘ for property ‘jobFactory‘; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [org.quartz.spi.JobFactory] for
property ‘jobFactory‘: no matching editors or conversion strategy found
Caused by: java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [org.quartz.spi.JobFactory] for property ‘jobFactory‘: no matching editors or conversion strategy found

這是一個非常小的bug,沒想到我剛開始卻沒註意到哪錯了.

錯誤代碼:

<property name="jobFactory" value="jobFactory"/>

正確代碼:

<property name="jobFactory" ref="jobFactory"/>
看出來了麽?將string類型轉換成所需要的class類型的轉換錯誤

是value和ref寫錯了.

理論上,ref是用在,當前xml中先前已經配置了<bean>標簽的,由於我的ssh框架使用的是註解開發,[email protected]("jobFactory")裏面的jobFactory即可.

在spring配置文件裏面,value配置的參數,一般是用在數字,字符串之類的,而不能放對象.而ref是存的是對象的引用!

特以此幾年今天所犯的錯誤.與君共勉.

關於spring的applicationContext.xml配置文件的ref和value之自我想法