Spring和redis的整合測試
1.專案匯入spring_test和junit包.(使用maven直接在pom檔案中新增).
<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>4.2.5.RELEASE</version> </dependency>
2.寫測試類,使用spring_test包進行測試,如果只用JUnit測試,需要每次初始化一下applicationContext,效率比較底下,而且也有不足之處,(這裡locations是個陣列,可以新增連個類路徑)
@ContextConfiguration(locations = {"classpath:conf/service/nyku-appContext-config.xml","classpath:conf/globals.datasource.xml"})
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "classpath:appContext-config.xml") public class RedisTest { @Resource private RedisUtil<String, Object, Serializable> redisUtil; @Test public void test() { } }
3.spring配置redis的方式
<beans 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:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"> <import resource="redis-config.xml"/> </beans>
4.redis的配置
<?xml version="1.0" encoding="UTF-8"?>
<beans 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:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<bean id="connectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="hostName" value="127.0.0.1"/>
<property name="port" value="6379"/>
</bean>
<bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
<property name="connectionFactory" ref="connectionFactory"/>
<property name="keySerializer">
<bean
class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
</property>
<property name="hashKeySerializer">
<bean
class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
</property>
</bean>
<bean name="redisAppUtil"
class="com.gaofei.core.server.framework.cache.redis.RedisUtilImpl">
<property name="redisTemplate">
<ref bean="redisTemplate"/>
</property>
</bean>
</beans>
redis的一些引數說明
//Redis伺服器IP
private static String ADDR = "192.168.0.100";
//Redis的埠號
private static int PORT = 6379;
//訪問密碼
private static String AUTH = "admin";
//可用連線例項的最大數目,預設值為8;
//如果賦值為-1,則表示不限制;如果pool已經分配了maxActive個jedis例項,則此時pool的狀態為exhausted(耗盡)。
private static int MAX_ACTIVE = 1024;
//控制一個pool最多有多少個狀態為idle(空閒的)的jedis例項,預設值也是8。
private static int MAX_IDLE = 200;
//等待可用連線的最大時間,單位毫秒,預設值為-1,表示永不超時。如果超過等待時間,則直接丟擲JedisConnectionException;
private static int MAX_WAIT = 10000;
private static int TIMEOUT = 10000;
//在borrow一個jedis例項時,是否提前進行validate操作;如果為true,則得到的jedis例項均是可用的;
private static boolean TEST_ON_BORROW = true;
相關推薦
spring 和 redis整合,並且使用redis做session快取伺服器
所需jar commons-pool2-2.0.jar jedis-2.9.0.jar spring-data-redis-1.6.2.RELEASE.jar spring-session-1.2.1.RELEASE.jar 一 . xml配
Spring和redis的整合測試
1.專案匯入spring_test和junit包.(使用maven直接在pom檔案中新增). <dependency> <groupId>junit</grou
spring junit4和junit5整合測試,3步走
1、導包spring-test-5.0.7.RELEASE.jar 2、使用註解改變執行main函式 3、指定spring的配置檔案 junit4示範程式碼 //改變junit的執行Runner
spring-boot 和 redis 整合的一個小例子
轉自:http://blog.csdn.net/a67474506/article/details/52595053 在網上看到好多的spring-boot和redis整合的,弄到本地一直報Error resolving template "get", template m
深入淺出JMS(四)--Spring和ActiveMQ整合的完整實例
訂閱 實例 schema -i 同步和異步 生產 技術分享 .com factor 第一篇博文深入淺出JMS(一)–JMS基本概念,我們介紹了JMS的兩種消息模型:點對點和發布訂閱模型,以及消息被消費的兩個方式:同步和異步,JMS編程模型的對象,最後說了JMS的優點。 第二
Spring和ActiveMQ整合的完整實例
beans util caching consumer str blank prop ner 消息發送 Spring和ActiveMQ整合的完整實例 前言 這篇博文,我們基於Spring+JMS+ActiveMQ+Tomcat,做一個Spring4.1.0和Acti
Swagger2和springMVC整合測試
inter encoding src mybatis project constrain aop servle efault 對Swagger寫個獨立的工程測試,方便後續進行工程的整合,這裏做一下記錄 1.pom.xml--依賴的的包 1 <project xm
Spring和mybatis整合 org.mybatis.spring.mapper.MapperScannerConfigurer
註冊 rop repo html itl tar hive mybatis property 在springmvc與mybatis整合時,需要對每一個mapper定義對應的一個MapperFactoryBean,可以使用MapperScannerConfigurer自動掃描
Spring 和Mybatis 整合
inter 映射文件 rem sna import enc -m lap sql 首先我們創建一個Java Project,名稱任意,然後導入所需要包:spring3.1.1, mybatis-3.1.1.jar, mysql-connector-java-5.1.2-be
spring和mybatis整合
ans int idle iso face 整合 testin pac 主配置文件 1 spring和mybatis整合 1.1 整合思路 需要spring通過單例方式管理SqlSessionFactory。 持久層的mapper都需要由spring進行管理
spring和mybatis整合小案例
http myba 效果展示 圖片 tro col mybatis 登錄模塊 -c 案例效果展示: 登錄模塊: 用戶註冊模塊: spring和mybatis整合小案例
sringboot和redis整合
專案結構 RedisConfig.java package com.fengqing.aalspringbootredis.config; import org.springframework.context.annotation.Bean; import org.springfra
spring 與 redis 整合及使用
1、實現目標 通過redis快取資料。(目的不是加快查詢的速度,而是減少資料庫的負擔) 2、所需jar包 注意:jdies和commons-pool兩個jar的版本是有對應關係的,注意引入jar包是要配對使用,否則將會報錯。因為commons-pooljar的目錄根據
spring和spirngmvc整合
<!-- 需要進行 Spring 整合 SpringMVC 嗎 ? 還是否需要再加入 Spring 的 IOC 容器 ? 是否需要再 web.xml 檔案中配置啟動 Spring IOC 容器的 ContextLoaderListener ? 1. 需要: 通常情況下, 類似於資料來源, 事務, 整
Spring和Hibernate整合xml配置
1、基於xml的配置 dbconfig.properties資料來源檔案配置 driverClass=com.mysql.jdbc.Driver jdbcUrl=jdbc:mysql://localhost:3306/databaseName user=root pass
Quartz學習——Spring和Quartz整合詳解(三)
Spring是一個很優秀的框架,它無縫的集成了Quartz,簡單方便的讓企業級應用更好的使用Quartz進行任務的排程。下面就對Spring整合Quartz進行簡單的介紹和示例講解!和上一節 Quartz學習——2、簡單入門示例Demo 的流程相似,介紹Spring和Quar
Ruby安裝和Redis整合
2. 安裝Ruby,以rubyinstaller-2.2.6-x64.exe為例,注意:安裝時記得選上新增系統路徑,否則需要手工修改Path 3. 確認安裝是否成功 (1)刪掉原來所有的源,預設外國源,國內無法訪問 gem sources --remo
初始quartz(spring和quartz整合)
初識quartz quartz是完全由java開發的一個開源的任務日程管理系統,“任務進度管理器”就是一個在預先確定(被納入日程)的時間到達時,負責執行(或者通知)其他軟體元件的系統。 1.quartz有兩種儲存方式: RAM儲存和JDBC儲存,顯然ram儲存就
spring和struts整合
2015-05-27 周海漢 2015.5.27 目錄結構: [email protected] % ls WebContent src [email protected] % find . . ./.c
spring-data-redis整合redis叢集配置
Spring版本:4.3.21.RELEASE spring-data-redis版本: <dependency> <groupId>org.springframework.data</groupId> <artifactId>sp