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 ...
随机推荐
- python之os和sys模块的区别
一.os模块 os模块是Python标准库中提供的与操作系统交互的模块,提供了访问操作系统底层的接口,里面有很多操作系统的函数 1.os常用方法 import os # print(os.getcwd ...
- bug_ warning: control reaches end of non-void function
摘要 在leetcode上编译时,它显示我编译错误 warning: control reaches end of non-void function 它的意思是:控制到达非void函数的结尾.就是说 ...
- 推荐几个树莓派 raspbian 系统 可用的 arm docker源
树莓派刚到手各种尝鲜,试过不少系统,最后还是回归了raspbian os 系统 root@raspberrypi:/home/pi# cat /proc/version Linux version 4 ...
- CAD安装错误1625:系统策略禁止这个安装,请与系统管理员联系。
在安装Autodesk CAD/3DMAX/Maya/Revit/Inventor等的时候,出现“安装错误1625:系统策略禁止这个安装,请与系统管理员联系.”,或是Error 1625,同时还会提示 ...
- mysql首次使用过程以及彻底卸载过程
安装过程: 步骤一: 安装mysql服务,使用命令行: yum install mysql-server 步骤二: 启动mysql服务: service mysqld start 确认msyql是否启 ...
- spring security梳理
核心服务:AuthenticationManager,UserDetailsService和AccessDecisionManager The AuthenticationManager, Provi ...
- HDU-2511-汉诺塔 X
首先我们来求第m次移动的盘子号数,先列出当m比较小可以直接观察的前几项 m : 1.2.3.4.5.6.7.8.9.10 id : 1.2.1.3.1.2.1.4.1.2 很容易联想到树状数组的low ...
- http,tcp,udp的报文格式
http请求报文与响应报文:https://blog.csdn.net/qq_26565861/article/details/80969960 tcp与udp报文:https://www.cnblo ...
- 使用JDBC CallableStatements执行存储过程
Using JDBC CallableStatements to Execute Stored Procedures Connector / J完全实现了 java.sql.CallableState ...
- javaWeb简单登录实现验证数据库
用户登录案例需求: 1.编写login.html登录页面 username & password 两个输入框 2.使用Druid数据库连接池技术,操作mysql,day14数据库中user表 ...