做过大型软件系统的同学都知道,随着系统数据越来越庞大,越来越复杂,随之带来的问题就是系统性能越来越差,尤其是频繁操作数据库带来的性能损耗更为严重。很多业绩大牛为此提出了众多的解决方案和开发了很多框架以优化这种频繁操作数据库所带来的性能损耗,其中,尤为突出的两个缓存服务器是Memcached和复述。今天,我们不讲Memcached和复述本身,这里主要为大家介绍如何使弹簧与复述整合。
<强> 1,pom构建强>
& lt;项目xmlns=" http://maven.apache.org/POM/4.0.0 " xmlns: xsi=" http://www.w3.org/2001/XMLSchema-instance " xsi: schemaLocation=" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd”比; & lt; modelVersion> 4.0.0 & lt; groupId> com.x.redis & lt; artifactId> springredis & lt; version> 0.0.1-SNAPSHOT & lt; dependencies> & lt; dependency> & lt; groupId> org.springframework.data & lt; artifactId> spring-data-redis & lt; version> 1.0.2.RELEASE & lt;/dependency> & lt; dependency> & lt; groupId> org.springframework & lt; artifactId> spring-test & lt; version> 3.1.2.RELEASE & lt; scope> test & lt;/dependency> & lt; dependency> & lt; groupId> redis.clients & lt; artifactId> jedis & lt; version> 2.1.0 & lt;/dependency> & lt; dependency> & lt; groupId> junit & lt; artifactId> junit & lt; version> 4.8.2 & lt; scope> test & lt;/dependency> & lt;/dependencies> & lt;/project> >之前<强> 2,春天配置文件(中)强>
& lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比; & lt;豆类xmlns=" http://www.springframework.org/schema/beans " xmlns: xsi=" http://www.w3.org/2001/XMLSchema-instance " xmlns: p=" http://www.springframework.org/schema/p " xmlns:上下文=" http://www.springframework.org/schema/context " xmlns: jee=" http://www.springframework.org/schema/jee " xmlns: tx=" http://www.springframework.org/schema/tx " xmlns: aop=" http://www.springframework.org/schema/aop " xsi: schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd”比; & lt;上下文:property-placeholder位置="类路径:复述。属性”/比; & lt; bean id=皃oolConfig”类=皉edis.clients.jedis.JedisPoolConfig”比; & lt;属性名=" maxIdle " value=" https://www.yisu.com/zixun/$ {redis.maxIdle} "/比; & lt;属性名=" maxActive " value=" https://www.yisu.com/zixun/$ {redis.maxActive} "/比; & lt;属性名=" maxWait " value=" https://www.yisu.com/zixun/$ {redis.maxWait} "/比; & lt;属性名=" testOnBorrow " value=" https://www.yisu.com/zixun/$ {redis.testOnBorrow} "/比; & lt;/bean> & lt; bean id=癱onnectionFactory”类=皁rg.springframework.data.redis.connection.jedis.JedisConnectionFactory” p:主机名=" ${复述。主机}”p:端口=" ${复述。港口}”p:密码=" ${复述。通过}poolConfig“p: pool-config-ref=/比; & lt; bean id=皉edisTemplate”类=皁rg.springframework.data.redis.core.StringRedisTemplate”比; & lt;属性名=" connectionFactory " ref=" connectionFactory "/比; & lt;/bean> & lt; bean id=皍serDao”类=" com.lyz.dao.impl。UserDaoImpl”/比; & lt;/beans> >之前<强> 3,复述。属性强>
#复述,设置 redis.host=192.168.157.130 redis.port=6379 redis.pass=liuyazhuang redis.maxIdle=300 redis.maxActive=600 redis.maxWait=1000 redis.testOnBorrow=true >之前<>强4、用户实体类强>
包com.lyz.entity; 进口java.io.Serializable;/* * *用户实体类 * @author liuyazhuang * */公开课用户实现了Serializable { 私有静态最终长serialVersionUID=-6011241820070393952 l; 私人字符串id; 私人字符串名称; 私人密码字符串; 公共用户(){ } 公共用户(字符串id、字符串名称字符串密码){ 超级(); 这一点。id=id; this.name=名称; 这一点。密码=密码; }/* * *获得id * @return id */公共字符串getId () { 返回id; }/* * *设置id * @param id id设置 */公共空间setId (String id) { 这一点。id=id; }/* * *获得名字 * @return名称 */公共字符串getName () { 返回名称; }/* * *设置的名字 * @param名称设置的名称 */公共空间setName(字符串名称){ this.name=名称; }/* * *获得密码 * @return密码 */公共字符串getPassword () { 返回密码; }/* * *设置密码 * @param密码的密码设置 */公共空间向setPassword(字符串密码){ 这一点。密码=密码; } }春天整合复述完整实例代码