redis如何在spring里面的bean配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<!--redis连接池配置 -->
<!--redis 配置 开始 -->
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<!-- 最大活动数目 -->
<property name="maxActive" value="300" />
<!-- 最大空数 -->
<property name="maxIdle" value="100" />
<!-- 最大等待时间 -->
<property name="maxWait" value="1000" />
<!-- true -->
<property name="testOnBorrow" value="true" />
</bean>
<bean id="jedisPool" class="redis.clients.jedis.JedisPool"
destroy-method="destroy">
<constructor-arg ref="jedisPoolConfig" />
<constructor-arg value="127.0.0.1" />
<constructor-arg value="6379" />
<constructor-arg value="3000" />
<!-- pass -->
<constructor-arg value="1234" />
<constructor-arg value="0" />
</bean>
<!-- RedisApi -->
<bean id="redisApi" class="cn.geekss.redis.RedisApi">
<property name="jedisPool" ref="jedisPool"></property>
</bean>
<!-- 配置tokenservice -->
<bean id="tokenService" class="cn.geekss.auth.TokenServiceImpl">
<property name="redisApi" ref="redisApi"></property>
</bean>
</beans>
RedisApi类文件
package cn.geekss.redis;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
/**
*
* @author ljn
* @date 2017-10-20
* @vesion 1.0
* @detail api 类
*/
public class RedisApi {
protected JedisPool jedisPool;
public JedisPool getJedisPool() {
return jedisPool;
}
public void setJedisPool(JedisPool jedisPool) {
this.jedisPool = jedisPool;
}
/**
* 赋值
*
* @param key
* @param value
* @return
*/
public boolean set(String key, String value) {
Jedis jedis = jedisPool.getResource();
try {
jedis.set(key, value);
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
/**
* 設置有效期時間
*
* @param key
* @param seconds
* @param value
* @return
*/
public boolean set(String key, int seconds, String value) {
Jedis jedis = jedisPool.getResource();
try {
jedis.setex(key, seconds, value);
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
/**
* 判断指定key是否存在
*
* @return
*/
public boolean exists(String key) {
try {
Jedis jedis = jedisPool.getResource();
return jedis.exists(key);
} catch (Exception e) {
// TODO: handle exception
}
return false;
}
/**
* 获取数据
*
* @param key
* @return
*/
public String get(String key) {
Jedis jedis = jedisPool.getResource();
try {
return jedis.get(key);
} catch (Exception e) {
// TODO: handle exception
}
return null;
}
/*
* 删除指定key
*/
public boolean del(String key) {
try {
Jedis jedis = jedisPool.getResource();
jedis.del(key);
return true;
} catch (Exception e) {
// TODO: handle exception
}
return false;
}
}
redis如何在spring里面的bean配置的更多相关文章
- spring里面的ioc的理解?
spring里面的ioc就是控制反转,其实现核心是DI(依赖注入),控制反转不向以前java代码里面,通过new关键字来实现创建对象,这样每段代码之间的耦合度就比较高,为了降低每个小模块之间的耦合度, ...
- Spring中的Bean配置方式
1.IOC和DI概述 IOC(Inversion of Control):其思想是反转资源获取的方向. 传统的资源查找方式要求组件向容器发起请求查找资源. 作为回应, 容器适时的返回资源. 而应用了 ...
- Spring 中的 Bean 配置
内容提要 •IOC & DI 概述 •配置 bean –配置形式:基于 XML 文件的方式:基于注解的方式 –Bean 的配置方式:通过全类名(反射).通过工厂方法(静态工厂方法 & ...
- Spring中的Bean配置
IOC&DI概述 OPC(Inversion of Control):其思想是反转资源获取的方向.传统的资源查找方式要求组件向容器发起请求查找资源.作为回应,容器适时的返回资源.而应用了IOC ...
- 如何在 Apache 里修改 PHP 配置
当使用 PHP 作为 Apache 模块时,也可以使用 Apache 配置文件(例如:httpd.conf) 和 .htaccess 文件中的指令来修改 PHP 的配置 设定,不过需要有 " ...
- nginx里面的rewrite配置
哎,我需要静静,刚刚在去怎么优化dom层级,发现更新完代码,层级又蹭蹭蹭的往上涨,顿时没脾气了,还是把昨天的nginx配置总结下,增加点动力,昨天前天两天都在搞这个问题,也是搞的没脾气,网上查了很多资 ...
- spring里面的context:component-scan
原文:http://jinnianshilongnian.iteye.com/blog/1762632 component-scan的作用的自动扫描,把扫描到加了注解Java文件都注册成bean &l ...
- 获取spring里的bean
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring. ...
- 通过类名获取spring里的Bean
import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactor ...
随机推荐
- hdu5452
http://acm.hdu.edu.cn/showproblem.php?pid=5452 题意:给个图T(图G的最小生成树),然后再给定图G的剩余边,问你从图T中当且割一条边的情况再割图G中不属于 ...
- text-align和vertical-align
1.text-align(水平对齐)text-align样式使元素在其定界区域内水平对齐,其取值可以是left.right.center或justify.justify使元素两端对齐.2.vertic ...
- Angular开发者指南(四)控制器
了解控制器controller 在AngularJS中,Controller由JavaScript构造函数定义,用于扩充AngularJS Scope. 当控制器通过ng-controller指令连接 ...
- understanding android build layer · Dylan
build / android 先看看Android官方的解释 Understand Build Layers The build hierarchy includes the abstraction ...
- 关闭”xx程序已停止工作”提示窗口
运行注册表编辑器,依次定位到HKEY_CURRENT_USER\Software\Microsoft\Windows\WindowsError Reporting,在右侧窗口中找到并双击打开Donts ...
- tf.estimator
estimator同keras是tensorflow的高级API.在tensorflow1.13以上,estimator已经作为一个单独的package从tensorflow分离出来了.estimat ...
- SQL语言基础及数据库的创建
一.数据类型:1.二进制数据二进制数据以十六进制形式存储.二进制数据最多能存8000个英文字符,4000个汉字字符. 2.字符数据char:存100,不足100补足.varcha:存多少占多少. 3. ...
- Catalan数应用问题
- 录音文件lame转换MP3相关配置
文件下载整个功能完成了,那么对应的文件上传也跑不了.So~ Look here~ 业务需求是录制音频然后上传到七牛并且Android可以读. 与安卓沟通了一下统一了mp3格式,大小质量都不错.由于AV ...
- 纯css3配合vue实现微信语音播放效果
前言 每次写点东西都扯两句-0-,这几天一半精力放在移动端,一半维护之前的项目.书也少看了,不过还好依旧保持一颗学习的心.对于css3我是之前有专门整理过的,因此对于原理之前也算了解.今天是项目中遇到 ...