天天看點

Initialization of bean failed; nested exception is org.springframework.beans.factory.: 錯誤分析

按照之前調試成功的兩個表關聯,加入更多的表,今天加入一個表,就出現以下錯誤

Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException:

Error creating bean with name 'sessionFactory' defined in file […….xml]: Invocation of init method failed;

nested exception is org.hibernate.HibernateException:

Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]

在網上查找了原因

可能原因如下:

1.真的沒有寫getter方法(發生幾率:1%)

2.*.hmb.xml檔案中的屬性名和pojo不一緻(*.hbm.xml和*.java沒銜接好,不一緻),字段屬性沒有正确配置,

比如,*.hmb.xml中*.java的位址要明确(明确指出引用包的完整路徑);映射錯誤;有多個主鍵時,對生成的聯合主鍵配置錯誤;

拼寫錯誤(包括多空格)等(發生幾率:48%)

3.方法寫錯/方法名寫錯,要按照javabean的書寫規範寫啊,要不然打死也找不到哪兒錯了(發生幾率:50%)

這裡提一下:get/set是不是不允許方法名中有連續兩個大寫字母,例如

public String getODPType(){

       return this.oDPType;

}

public void setODPType(String  oDPType){

this.oDPType = oDPType;

這樣寫它就會報錯,報找不到getter for oDPType的錯誤,但下面這樣寫就可以了

public String odpType;

public String getOdpType(){

       return this.odpType;

public void setOdpType(String      odpType){

this.odpType = odpType;