spring中配置hibernate缓存
JAVA学习 2009-11-02 11:44:21 阅读103 评论0 字号:大中小
1.首先,在spring的hibernate配置里(我的是applicationContext-hibernate.xml) 加上如下属性:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<property name="mappingResources">
<list>
<value>org/appfteaching/model/TArticleclass.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.jdbc.fetch_size">${hibernate.jdbc.fetch_size}</prop>
<prop key="hibernate.jdbc.batch_size">${hibernate.jdbc.batch_size}</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
</props>
</property>
</bean>
2.其次,在src目录下的ehcache.xml中配置如下信息(如果是默认ehcache.xml则会有<cache name="sampleCache1">和<cache name="sampleCache2>",去掉)
<cache name="org.hibernate.cache.StandardQueryCache"
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="300"
timeToLiveSeconds="4200"
overflowToDisk="true"
/>
<!-- Sample cache named sampleCache2
This cache contains 1000 elements. Elements will always be held in memory.
They are not expired. -->
<cache name="org.hibernate.cache.UpdateTimestampsCache"
maxElementsInMemory="5000"
eternal="true"
timeToIdleSeconds="0"
timeToLiveSeconds="0"
overflowToDisk="false"
/>
3.将你要缓存的model加进ehcache.xml里
<cache name="org.appfteaching.model.TArticleclass"
maxElementsInMemory="1000"
eternal="false"
timeToIdleSeconds="100"
timeToLiveSeconds="4200"
overflowToDisk="true"
/>
4.最后一步,在TArticleclass.hbm.xml里加上
<cache usage="read-write"/> or <cache usage="nonstrict-read-write"/>
5.在DAO中,调用find方法查询之前,设置使用缓存
java 代码
getHibernateTemplate().setCacheQueries(true);
启动Tomcat,如发现如下错误
Could not find configuration [org.hibernate.cache.UpdateTimestampsCache]; using defaults.
Could not find configuration [org.hibernate.cache.StandardQueryCache]; using defaults.
则是第二步没有做,加上即可.配置完毕
spring中配置二级缓存
分享到:
相关推荐
传播智客,为Spring集成的Hibernate配置二级缓存、cache.xml
此配置和包,是springMVC4.3.3 +spring4+hibernate5.1.3+二级缓存ehcache(不用可以关闭)+fastjson。 是正常运行的项目里拷出来的,方便大家使用。
为Spring集成的Hibernate配置二级缓存
Spring4+Hibernate4二级缓存实例源码.
NULL 博文链接:https://jyao.iteye.com/blog/1299178
memcache的客户端,用maven构建,里有用hibernate-memcached与hibernate,spring3.0进行配置,也有与spring3.0单独配置。
在Spring+Hibernate集成环境中使用EhCache缓存做的开发测试,在线程中打开数据库查询数据,及关闭数据库后查询数据的结果.
7:Hibernate查询缓存Query Cache及实现
基于springboot最新版本2.1.4.RELEASE,采用jpa为dao层框架,配置redis(redisson)为hibernate的二级缓存。
其中包含apache的log4j记录日志信息,spring管理组件,springmvc分层,springaop配置数据库事务控制,hibernate二级缓存配置,实现了查询,用户登录注册,请求验证是否登录等基础功能Demo,基于后台测试,使用前台...
本版本全面更新了jar包,全部使用了当前最新版本的jar包,struct2.1.8 spring3 hibernate3.5,全面使用注解取代xm的l配置。 另外增加了一个ant构建脚本,支持使用hudson完成每日构建,持续集成,自动测试,代码规范...
5.单数据源配置(兼容Tomcat和Weblogic)。 6.Hibernate继承 HibernateDaoSupport。 7.Spring+Junit4单元测试,优点:不会破坏数据库现场,等等。 2)Demo 导入说明: 1.Eclipse Encoding:GBK 2.Eclipse 导入后可能...
架构技术: struts2+spring3+hibernate4 + UI 组件(easyui)+Spring_security权限 配置思想: Convention 零配置(不需要任何配置文件) 优点; [1].代码生成器(单表的增删改查完美生成) 注意:包括JSP页面的生成...
使用spring+mvc+hibernate集成redis缓存,如有需要详细使用阅读内容可以访问我的博客来查看http://blog.csdn.net/wohuozheng?ref=toolbar
2. 在 applicationContext.xml 文件中找到 sessionFactory 相应的配置信息并在设置 hibernateProperties 中添加如下代码: <!-- 配置使用查询缓存 --> <prop key=hibernate.cache.use_query_cache>true <!...
完整的spring +springmvc+hibernate+shiro项目实例,详细的shiro配置介绍,通过redis管理用户session缓存。。。。。。。。
本版本全面更新了jar包,全部使用了当前最新版本的jar包,struct2.1.8 spring3 hibernate3.5,全面使用注解取代xm的l配置。 另外增加了一个ant构建脚本,支持使用hudson完成每日构建,持续集成,自动测试,代码规范...
此项目整合了目前主流和最前源的web开发技术:采用ehcache实现二级缓存(包含查询缓存);用sf4j及logback(log4j的升级版)记录日志;proxool(据说是dbcp和c3p0三者中最优秀的)做连接池;使用jquery的ajax实现仿...
NULL 博文链接:https://8366.iteye.com/blog/470815
Spring3.2 Hibernate4.2 JPA2全注解实例.采用JTA事务管理,配置ehcache为二级缓存,在glassfish3.2.2和postgresql9测试通过。参考网上的资料整理。