Spring 整合Hibernate时报错:

org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'sessionFactory' defined in class path resource [spring/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'annotatedClasses' of bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]:
Bean property 'annotatedClasses' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

 

......

原因在于选择Hibernate的sessionFactory时有两种:

1. LocalSessionFactoryBean,使用*.hbm.xml进行配置。而且bean的class是hibernate3.LocalSessionFactoryBean:

	<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="mappingResources">
<list>
<value>User.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect"> org.hibernate.dialect.MySQLDialect </prop>
</props>
</property>
</bean>

2. AnnotationSessionFactoryBean。bean的class是AnnotationSessionFactoryBean

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses</span>">
<list>
<value>com.xxx.model.User</span></value>
</list>
</property>
<property name="hibernateProperties">
<!-- <value>
hibernate.dialect=org.hibernate.dialect.HSQLDialect
</value> -->
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>

在获取session的时候,使用Session s = sessionFactory.openSession();

Spring整合Hibernate报错:annotatedClasses is not writable or has an invalid setter method的更多相关文章

  1. spring整合quartz报错

    今天spring整合quartz报错,最后一步步排查,发现是和redis依赖冲突,最后redis升级了一下,问题解决. 总结:发现问题,逐一排查,如果是整合问题,报类加载不到的错误,大概率是和其他组件 ...

  2. spring整合junit报错

    1.Could not autowire field: private javax.servlet.http.HttpServletRequest 参考:https://www.cnblogs.com ...

  3. spring整合hibernate时报错:org.hibernte.engine.transaction.spi.transactioncontext

    错误提示:Caused by:java.lang.ClassNotFoundException: org.hibernte.engine.transaction.spi.transactioncont ...

  4. spring+hibernate整合:报错org.hibernate.HibernateException: No Session found for current thread

    spring+hibernate整合:报错信息如下 org.hibernate.HibernateException: No Session found for current thread at o ...

  5. 【Java EE 学习 53】【Spring学习第五天】【Spring整合Hibernate】【Spring整合Hibernate、Struts2】【问题:整合hibernate之后事务不能回滚】

    一.Spring整合Hibernate 1.如果一个DAO 类继承了HibernateDaoSupport,只需要在spring配置文件中注入SessionFactory就可以了:如果一个DAO类没有 ...

  6. spring整合hibernate

    spring整合hibernate包括三部分:hibernate的配置.hibernate核心对象交给spring管理.事务由AOP控制 好处: 由java代码进行配置,摆脱硬编码,连接数据库等信息更 ...

  7. Spring整合Hibernate笔记

    1. Spring 指定datasource a) 参考文档,找dbcp.BasicDataSource i. c3p0 ii. dbcp <bean id="dataSource&q ...

  8. Spring整合Redis时报错:java.util.NoSuchElementException: Unable to validate object

    我在Spring整合Redis时报错,我是犯了一个很低级的错误! 我设置了Redis的访问密码,在Spring的配置文件却没有配置密码这一项,配置上密码后,终于不报错了!

  9. Spring整合Hibernate的XML文件配置,以及web.xml文件配置

    利用Spring整合Hibernate时的XML文件配置 applicationContext.xml <?xml version="1.0" encoding=" ...

随机推荐

  1. Python for Eclipse插件Pydev安装后eclipse里面看不到

    反复安装几次在eclipse里面都找不到,崩溃了,有的说是pydev版本不对,应该和python版本一致,都是扯淡,去pydev官网看了下requirement原来是需要Java1.7+以上,安装1. ...

  2. 基于虚拟用户登录的ftp服务配置

    文章结构:             一.使用逻辑卷配置ftp数据存放目录             二.安装和配置vsftpd服务             三.使用不通权限的用户访问ftp服务器 系统环 ...

  3. [fw]用Kprobes调试(debug)内核

    Kprobes是一种运行时动态调试内核的机制, 你可以用它设置断点并收集调试信息, 甚至改变内核行为. Kprobes分三种, 普通kprobes以及基于普通kprobes的jprobes和kretp ...

  4. Windows开发,关于通过写代码加载PDB的那些事

    最近,接到一个活,要写一个程序,用来批量分析一堆dll和对应的PDB, 其实工作很简单,就是根据一堆偏移,通过PDB文件,找到对应dll里面对应位置的明文符号, 简单的需求,实现起来,通常都很麻烦, ...

  5. etcd扩展使用

    etcd我已经提到很多次了,前面的可以自己查看.v3版本改用grpc接口,很简单,非常简单,易上手易学习. etcd有集群部署方式,那么就涉及部署的地址,可以动态添加部署节点,这样再应用中不可能都去关 ...

  6. 小程序中为什么使用var that=this

    前言: 在小程序或者js开发中,经常需要使用var that = this;开始我以为是无用功,(原谅我的无知),后来从面向对象的角度一想就明白了,下面简单解释一下我自己的理解,欢迎指正批评. 代码示 ...

  7. 【转载】Elasticsearch--java操作之QueryBuilders构建搜索Query

    原文地址:https://www.cnblogs.com/pypua/articles/9459941.html package com.elasticsearch; import org.elast ...

  8. 分支结构case 语句语法

  9. Rsync备份服务实战

    目录 Rsync备份服务实战 一.Rsync 二.rsync的应用场景 1.Rync的数据同步模式 2.rsync的三种模式 三.rsync配置服务端客户端 四.rsync实战 实战一 报错解决方法: ...

  10. css3--css3模块

    CSS3被拆分为"模块".旧规范已拆分成小块,还增加了新的. 一些最重要CSS3模块如下: 1.选择器(.基本选择器,层次选择器,伪类选择器,伪元素,属性选择器,通配符) 2.盒模 ...