hibernate memcached

配置memcached所需jar(这里采用hibernate-memcached.*.jar):
[size=medium][color=blue]1.hibernate-memcached-1.2.2.jar
2.memcached-2.3.1.jar[/size][/color]
在使用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如图:

[img]http://dl.iteye.com/upload/attachment/602932/afa4cef8-a71a-39fc-94d9-72450ccb0c64.jpg[/img]


接下来启动tomcat:

2011-12-09 00:06:03.690 [color=brown]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[/color]
[color=red]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[/color]
跟踪memcached输出信息如下:
[img]http://dl.iteye.com/upload/attachment/602934/22469e93-5db6-3917-a069-3ec52253b89e.png[/img]
附件中可下载相关jar和memcached client-windows。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值