解决org.springframework.beans.factory.BeanCreationException 异常的一种情况

最近在实战SSH项目,遇到一个错误,如下:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.ztg.elec.dao.impl.ElecTextDaoImpl': Injection of resource methods failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [beans.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]
....

.....

.....//一直纠结于上面的报错信息,忽略了下面错误信息
Caused by: org.hibernate.PropertyNotFoundException: Could not find a getter for textReamark in class com.ztg.elec.domain.ElecText
at org.hibernate.property.BasicPropertyAccessor.createGetter(BasicPropertyAccessor.java:328)
at org.hibernate.property.BasicPropertyAccessor.getGetter(BasicPropertyAccessor.java:321)
at org.hibernate.mapping.Property.getGetter(Property.java:304)
at org.hibernate.tuple.entity.PojoEntityTuplizer.buildPropertyGetter(PojoEntityTuplizer.java:299)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:158)
at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:77)
... 72 more

其实就是因为自己的粗心,在配置elecText.hbm.xml文件时,

<property name="textReamark" type="string">

    <column name="textRemark" sql-type="varchar(500)"></column>
   </property>,这里property中的name对应于bean类中的属性textRemark,所以这里应该写textRemark,而不是textReamark,

所以就报错了:其实应该耐心读懂报错信息,读到下面

Caused by: org.hibernate.PropertyNotFoundException: Could not find a getter for textReamark in class com.ztg.elec.domain.ElecText

才知道错误,然后修改后的正确配置是:

<property name="textRemark" type="string">

     <column name="textRemark" sql-type="varchar(500)"></column>
 </property>



总结:

在写hbm.xml配置文件的时候,

<property name="textRemark" type="string">中的name值bean类属性名应该一致,否则会报以上错误

而<column name="textRemark" sql-type="varchar(500)"></column>中的name值应该和数据库表中的列段名一致,否则在数据库表中会产生一个新列。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值