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 ...
随机推荐
- android选择器汇总、仿最美应用、通用课程表、卡片动画、智能厨房、阅读客户端等源码
Android精选源码 android各种 选择器 汇总源码 高仿最美应用项目源码 android通用型课程表效果源码 android实现关键字变色 Android ViewPager卡片视差.拖拽及 ...
- 在python的web框架Django中使用SQL Server
在pycharm中安装 安装pyodbc和Django——pyodbc是一个用python写的ODBC引擎 安装Django-pyodbc-azure 在后方网址中查 ...
- python语法基础-函数-基础-长期维护
############### 函数的定义调用,返回值和返回值接收 ############## def mylen(): s = "myname" i = 0 for ...
- 推送至远程仓库使用git push -u的原因
第一次把本地仓库推送至远端时,为了以后方便一定要使用 git push -u origin master [此处是把本地的master分支推送至远程的master分支]
- Java中的Properties类
目录 Java中的Properties类 前言 主要方法 读取Properties文件 相关实例 Java中的Properties类 前言 Java中的Properties类属于配置文件,以键值对的方 ...
- CSS性能优化探讨
大部分前端开发人员都不关心CSS性能优化,其实对于一个复杂的页面来说,高效的选择器还是可以带来一定的性能提升的. 1. CSS 选择器 浏览器是“从右往左”来分析 class 的,它的匹配规则是从右向 ...
- leetcode第22题:括号生成
力扣上的题目可以大致分为以下种类: 对某种复杂规则的彻底解析,很有可能要构造状态机,充分考虑边界情况. 对某种数据结构及算法的应用. 对数学概念.遍历.动态规划等的综合应用. 通过分析,本题应该属于1 ...
- fiddler模拟返回响应数据
通过find查找修改指定内容 选择find a file 保存后重新发起请求
- bubble chart|Matrix Scatter|Overlay Scatter|Scatterplots|drop-line|box plot|Stem-and-leaf plot|Histogram|Bar chart|Pareto chart|Pie chart|doughnut chart|
应用统计学 对类别数据要分类处理: Bar chart复式条形图便于对比: Pareto chart:对类别变量依据频数高低排列: Pie chart:饼图用于一个样本,可以区分类别数据 doughn ...
- 格式化MyEclipse代码(java、jsp、js)行的长度@修改java代码字体@修改Properties文件编码方式
每次用MyEclipse/Eclipse自带的快捷键Ctrl+shift+f格式化代码时,如果原来的一行代码大于80列,Eclipse就会自动换为多行.如果想格式化代码后不想让代码换行可以通过以下方式 ...