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. ftrace 使用方法

    1. 追蹤Kernel function (以schedule()示範) 先至 /sys/kernel/debug/tracing# cat available_tracers 確定有無 函式追蹤器( ...

  2. Java开发中的23种设计模式详解(2)结构型

    我们接着讨论设计模式,上篇文章我讲完了5种创建型模式,这章开始,我将讲下7种结构型模式:适配器模式.装饰模式.代理模式.外观模式.桥接模式.组合模式.享元模式.其中对象的适配器模式是各种模式的起源,我 ...

  3. vue证明题X,vue设置集

    1.开发中的控制台tab格式警告隐藏 出现情况如图: 解决方案:找到此代码,注释掉 2.控制台error报告 出现情况如图 解决方案:找到此代码,替换,对浏览器中的警告进行隐藏 遇到就更

  4. Primeng UI框架ionic3 中下拉选择插件p-dropdown 插件的使用方法

    1.html引入: <p-dropdown float-right [options]="sortOption" [(ngModel)]="sortNow" ...

  5. 【转载】linux查看端口状态相关命令

    具体命令移步:https://www.cnblogs.com/cxbhakim/p/9353383.html

  6. 函数传递是如何让HTTP服务器工作的

    var http = require("http"); http.createServer(function(request, response) { response.write ...

  7. vue学习笔记(五)— 组件通信

    关于vue父子组件通信 作者:狐狸家的鱼 本文链接:vue组件通信 GitHub:sueRimn 如果组件是一个单页面,组件之间存在父子关系,数据传递就需要根据父子不同的地位使用不同的办法. 借助新建 ...

  8. 使用 v-html 绑定值

    <div id="app03"> <div v-html="message"></div> <!--这里使用v-htm ...

  9. oracle的查询结果按照in条件顺序输出

    业务需要,通过lucene查出符合搜索条件的id,然后在详情表里查出这些id的详情 ? 1 SELECT id,QUESTION,QUESTIONCOMMENT FROM "ASKDBA_Q ...

  10. 【软工项目Beta阶段】绝不划水队OUC-Market版本测试报告

    我们在开发APP的时候进行了软件的测试,同时发现了一些BUG,如下: bug 我的:与各种页面之间的交互不灵活 登录与注册:记住密码功能不完善 商场主界面:搜索功能还没有完善 收藏功能:与数据库的交互 ...