配置memcached所需jar(这里采用hibernate-memcached.*.jar):
1.hibernate-memcached-1.2.2.jar
2.memcached-2.3.1.jar
在使用sping的情况下的配置:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.directwebremoting.org/schema/spring-dwr http://www.directwebremoting.org/schema/spring-dwr/spring-dwr-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<!-- spring annotation声明 -->
<context:annotation-config></context:annotation-config>
<context:component-scan base-package="com.sport"></context:component-scan>
<!-- 声明AOP -->
<aop:aspectj-autoproxy></aop:aspectj-autoproxy>
<!-- 声明可读取配置文件,在本XML中就可用${}取到xxx.properties文件的值 -->
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:jdbc.properties"></property>
</bean>
<!-- 配置数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName">
<value>${driver}</value>
</property>
<property name="url">
<value>${url}</value>
</property>
<property name="username">
<value>${username}</value>
</property>
<property name="password">
<value>${password}</value>
</property>
<property name="maxActive">
<value>${maxActive}</value>
</property>
<property name="minIdle">
<value>${minIdle}</value>
</property>
<property name="maxIdle">
<value>${maxIdle}</value>
</property>
</bean>
<!-- 配置session工厂,这里用spring提供的AnnotationSessionFactoryBean -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<!-- 指定实体类扫描包 -->
<property name="packagesToScan">
<list>
<value>com.sport.bean</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<!--hibernate memcached 配置-->
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.provider_class">com.googlecode.hibernate.memcached.MemcachedCacheProvider</prop>
<prop key="hibernate.memcached.servers">localhost:11211</prop>
<prop key="hibernate.memcached.cacheTimeSeconds">300</prop>
<!--<prop key="hibernate.hbm2ddl.auto">create</prop> -->
</props>
</property>
</bean>
<!-- 注入hibernateTemplate -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 事务管理器 -->
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
<property name="dataSource" ref="dataSource"></property>
</bean>
<!--使用基于注解方式配置事务 -->
<tx:annotation-driven transaction-manager="txManager"/>
</beans>
接下来启动memcached client如图:
接下来启动tomcat:
2011-12-09 00:06:03.690
INFO net.spy.memcached.MemcachedConnection: Added {QA sa=localhost/127.0.0.1:11211, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0} to connect queue
2011-12-09 00:06:03.707 INFO net.spy.memcached.MemcachedConnection: Connection state changed for sun.nio.ch.SelectionKeyImpl@a7ae01
2011-12-9 0:06:09 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory WebDemo
2011-12-9 0:06:09 org.apache.coyote.http11.Http11AprProtocol start
信息: Starting Coyote HTTP/1.1 on http-8080
2011-12-9 0:06:09 org.apache.coyote.ajp.AjpAprProtocol start
信息: Starting Coyote AJP/1.3 on ajp-8009
2011-12-9 0:06:09 org.apache.catalina.startup.Catalina start
信息: Server startup in 21838 ms
跟踪memcached输出信息如下:
附件中可下载相关jar和memcached client-windows。
- 大小: 25.5 KB
- 大小: 42.9 KB
分享到:
相关推荐
这个包是最高版本了,google code是1.22,但是这个版本是基础班的1.5版本.是github上源代码经过我打包出来的jar
用于hibernate集成memcached作为二级缓存所需要的包,1.2.2版本
memcached-2.5-sources.jar、hibernate-memcached-1.2.2-sources.jar、spy-2.4.jar这三个jar不太好找,剩下两个commons-codec和slf4j-log4j直接maven配置一下就行 <groupId>org.slf4j <artifactId>slf4j-log4j12 ...
hibernate-memcached, 在Hibernate中,使用Memcached作为第二级分布式缓存的库 休眠 memcachedHibernate中使用Memcached作为第二级分布式缓存的库。基于优秀的spymemcached客户端包含对 Whalin ( danga ) memcached...
hibernate-memcached-1.1.0-sources.zip
hibernate-memcached,一个分布式缓存框架,很强大,这里提供hibernate集成jar
hibernate-memcached-1.2.2.jar memcached-2.3.1.jar slf4j-api-1.7.12.jar slf4j-log4j12-1.5.0.jar
hibernate-memcached-1.1.0.jar
解决目前memcached不支持hibernate4的缺陷,hibernate配置<property name="hibernate.cache.region.factory_class">com.googlecode.hibernate.memcached.MemcachedRegionFactory</property>
hibernate使用memcached作为二级缓存所需要的资源包,包括memcached的windows安装文件、hibernate3和hibernate4整合memcached的jar包 文件目录:commons-codec-1.10.jar、hibernate3-memcached-1.5.jar、hibernate4-...
google上的这个包最多是1.2.2但是github上是1.3,源代码下载下来后,我打包为jar的
memcached作为hibernate二级缓存必备的jar包.包含hibernate-memcached-1.2.2.jar memcached-2.1.jar spy-2.4.jar
hibernate-memcached-1.1.0-javadoc.zip
memcache的客户端,用maven构建,里有用hibernate-memcached与hibernate,spring3.0进行配置,也有与spring3.0单独配置。
memcached整合hibernate资源合集
NULL 博文链接:https://dixian.iteye.com/blog/930677
这是maven工程,解压后直接导入eclipse,就可以使用了
项目使用Spring4+SpringMVC+mysql【同时支持mybatis+hibernate两种底层操作框架】+memcached
memcached-2.1.jar
ehcache 二级缓存 配置...<property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory 3.3配置如下: <property name="hibernate.cache.use_second_level_cache">true ...