- 浏览: 3431153 次
- 性别:
- 来自: 珠海
文章分类
- 全部博客 (1633)
- Java (250)
- Android&HTML5 (111)
- Struts (10)
- Spring (236)
- Hibernate&MyBatis (115)
- SSH (49)
- jQuery插件收集 (55)
- Javascript (145)
- PHP (77)
- REST&WebService (18)
- BIRT (27)
- .NET (7)
- Database (105)
- 设计模式 (16)
- 自动化和测试 (19)
- Maven&Ant (43)
- 工作流 (36)
- 开源应用 (156)
- 其他 (16)
- 前台&美工 (119)
- 工作积累 (0)
- OS&Docker (83)
- Python&爬虫 (28)
- 工具软件 (157)
- 问题收集 (61)
- OFbiz (6)
- noSQL (12)
最新评论
-
HEZR曾嶸:
你好博主,这个不是很理解,能解释一下嘛//左边+1,上边+1, ...
java 两字符串相似度计算算法 -
天使建站:
写得不错,可以看这里,和这里的这篇文章一起看,有 ...
jquery 遍历对象、数组、集合 -
xue88ming:
很有用,谢谢
@PathVariable映射出现错误: Name for argument type -
jnjeC:
厉害,困扰了我很久
MyBatis排序时使用order by 动态参数时需要注意,用$而不是# -
TopLongMan:
非常好,很实用啊。。
PostgreSQL递归查询实现树状结构查询
apache shiro集群实现(一) session共享 http://blog.csdn.net/michaelliuyang/article/details/8819852
apache shiro集群实现(二)— cache共享 http://blog.csdn.net/michaelliuyang/article/details/8820390
Redis整合Spring结合使用缓存实例 http://blog.csdn.net/evankaka/article/details/50396325
原文的修改: 很多人留言希望提供基础代码, 但原文的作者不愿意提供基础代码, 让人很纳闷, 所以自己找了很久, 决定替换和修改原文的代码
针对redis的session共享的配置或者源码
针对redis的cache的配置或源码
RedisUtil.java参考: http://panyongzheng.iteye.com/blog/2295435
apache shiro集群实现(二)— cache共享 http://blog.csdn.net/michaelliuyang/article/details/8820390
Redis整合Spring结合使用缓存实例 http://blog.csdn.net/evankaka/article/details/50396325
原文的修改: 很多人留言希望提供基础代码, 但原文的作者不愿意提供基础代码, 让人很纳闷, 所以自己找了很久, 决定替换和修改原文的代码
针对redis的session共享的配置或者源码
<bean id="jdkSerializationRedisSerializer" class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer"/> <bean id="stringRedisSerializer" class="org.springframework.data.redis.serializer.StringRedisSerializer"/> <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig"></bean> <bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"> <property name="hostName" value="192.168.0.198"/> <property name="port" value="6379"/> <property name="password" value="12345"/> <property name="timeout" value="1000"/> <property name="poolConfig" ref="jedisPoolConfig"/> <property name="usePool" value="true"/> </bean> <!-- GenericToStringSerializer: 可以将任何对象泛化为字符串并序列化 Jackson2JsonRedisSerializer: 跟JacksonJsonRedisSerializer实际上是一样的 JacksonJsonRedisSerializer: 序列化object对象为json字符串 JdkSerializationRedisSerializer: 序列化java对象 StringRedisSerializer: 简单的字符串序列化 --> <bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate"> <property name="connectionFactory" ref="jedisConnectionFactory"/> <property name="defaultSerializer" ref="jdkSerializationRedisSerializer" /> <property name="keySerializer" ref="stringRedisSerializer"/> <property name="hashKeySerializer" ref="stringRedisSerializer"/> <property name="valueSerializer" ref="jdkSerializationRedisSerializer"/> <property name="hashValueSerializer" ref="jdkSerializationRedisSerializer"/> </bean> <bean id="redisUtil" class="com.pandy.framework.base.redis.utils.RedisUtil"> <property name="redisTemplate" ref="redisTemplate"/> </bean>
package com.pandy.framework.base.shiro.session.dao.impl; import com.pandy.framework.base.redis.utils.RedisUtil; import com.pandy.framework.base.shiro.session.dao.ShiroSessionRepository; import org.apache.shiro.session.Session; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.Serializable; import java.util.Collection; import java.util.HashSet; import java.util.Iterator; import java.util.Set; /** * Created by pandy on 16-5-3. */ public class JedisShiroSessionRepository implements ShiroSessionRepository { private Logger logger = LoggerFactory.getLogger(JedisShiroSessionRepository.class); private RedisUtil redisUtil; /** * redis session key前缀 */ private final String REDIS_SHIRO_SESSION = "PANDY-WP-FRAMEWORK-SESSION"; private String redisShiroSessionPre; public void saveSession(Session session) { if (session == null || session.getId() == null) { logger.error("session或者session id为空"); return; } redisUtil.set(getRedisSessionKey(session.getId()), session); } public void deleteSession(Serializable id) { if (id == null) { logger.error("id为空"); return; } redisUtil.remove(getRedisSessionKey(id)); } public Session getSession(Serializable id) { if (id == null) { logger.error("id为空"); return null; } Session session = redisUtil.get(getRedisSessionKey(id), Session.class); return session; } public Collection<Session> getAllSessions() { Set<Session> sessions = new HashSet<Session>(); Set<String> set = redisUtil.getPatternKey("*"); if (set == null || set.size() == 0) return sessions; Iterator<String> it = set.iterator(); while (it.hasNext()) { try { String key = it.next(); if(key!=null && key.indexOf(REDIS_SHIRO_SESSION)>=0){ Session session = redisUtil.get(key, Session.class); sessions.add(session); } }catch (Exception e){ e.printStackTrace(); } } return sessions; } /** * 获取redis中的session key * * @param sessionId * @return */ private String getRedisSessionKey(Serializable sessionId) { return getRedisShiroSessionPre() + sessionId; } public RedisUtil getRedisUtil() { return redisUtil; } public void setRedisUtil(RedisUtil redisUtil) { this.redisUtil = redisUtil; } public String getRedisShiroSessionPre() { if (redisShiroSessionPre == null || redisShiroSessionPre.trim().length() == 0) { return REDIS_SHIRO_SESSION + ":"; } return REDIS_SHIRO_SESSION + "-" + redisShiroSessionPre + ":"; } public void setRedisShiroSessionPre(String redisShiroSessionPre) { this.redisShiroSessionPre = redisShiroSessionPre; } }
<!-- 使用redis处理会话DAO --> <bean id="jedisShiroSessionRepository" class="com.pandy.framework.base.shiro.session.dao.impl.JedisShiroSessionRepository"> <property name="redisUtil" ref="redisUtil"/> <property name="redisShiroSessionPre" value="PANDY_WEB_APP_SESSION"/> </bean> <bean id="sessionDAO" class="com.pandy.framework.base.shiro.session.dao.impl.CustomShiroSessionDAO"> <property name="shiroSessionRepository" ref="jedisShiroSessionRepository" /> <property name="sessionIdGenerator" ref="sessionIdGenerator"/> </bean>
针对redis的cache的配置或源码
package com.pandy.framework.base.shiro.cache; import com.pandy.framework.base.redis.utils.RedisUtil; import org.apache.shiro.cache.Cache; /** * Created by pandy on 16-5-4. */ public class JedisShiroCacheManager implements ShiroCacheManager { private RedisUtil redisUtil; private String redisShiroCachePre; public <K, V> Cache<K, V> getCache(String name) { return new JedisShiroCache<K, V>(name, redisUtil, getRedisShiroCachePre()); } public void destroy() { //jedisCacheManager.getJedis().shutdown(); throw new RuntimeException("这里要怎么实现啊,还不知道怎么实现"); } public RedisUtil getRedisUtil() { return redisUtil; } public void setRedisUtil(RedisUtil redisUtil) { this.redisUtil = redisUtil; } public String getRedisShiroCachePre() { return redisShiroCachePre; } public void setRedisShiroCachePre(String redisShiroCachePre) { this.redisShiroCachePre = redisShiroCachePre; } }
package com.pandy.framework.base.shiro.cache; import org.apache.shiro.cache.Cache; import org.apache.shiro.cache.CacheException; import org.apache.shiro.cache.CacheManager; import org.apache.shiro.util.Destroyable; /** * Created by pandy on 16-5-4. */ public class CustomShiroCacheManager implements CacheManager, Destroyable { private ShiroCacheManager shiroCacheManager; public ShiroCacheManager getShiroCacheManager() { return shiroCacheManager; } public void setShiroCacheManager(ShiroCacheManager shiroCacheManager) { this.shiroCacheManager = shiroCacheManager; } public <K, V> Cache<K, V> getCache(String name) throws CacheException { return getShiroCacheManager().getCache(name); } public void destroy() throws Exception { shiroCacheManager.destroy(); } }
package com.pandy.framework.base.shiro.cache; import com.pandy.framework.base.redis.utils.RedisUtil; import com.pandy.framework.base.utils.SerializeUtil; import org.apache.shiro.cache.Cache; import org.apache.shiro.cache.CacheException; import java.util.*; /** * Created by pandy on 16-5-4. */ public class JedisShiroCache<K, V> implements Cache<K, V> { private RedisUtil redisUtil; private final String REDIS_SHIRO_CACHE = "PANDY-WP-FRAMEWORK-CACHE"; private String redisShiroCachePre; private String name; public JedisShiroCache(String name, RedisUtil redisUtil, String redisShiroCachePre) { this.name = name; this.redisUtil = redisUtil; this.redisShiroCachePre = redisShiroCachePre; } /** * 自定义relm中的授权/认证的类名加上授权/认证英文名字 * * @return */ public String getName() { if (name == null) return ""; return name; } public void setName(String name) { this.name = name; } public V get(K key) throws CacheException { byte[] byteKey = SerializeUtil.serialize(getCacheKey(key)); //byte[] byteValue = redisUtil.get(getCacheKey(key)); Object byteValue = redisUtil.get(getCacheKey(key)); return (V) byteValue; } public V put(K key, V value) throws CacheException { V previos = get(key); redisUtil.set(getCacheKey(key), value); return previos; } public V remove(K key) throws CacheException { V previos = get(key); redisUtil.remove(getCacheKey(key)); return previos; } public void clear() throws CacheException { byte[] keysPattern = SerializeUtil.serialize(this.REDIS_SHIRO_CACHE + "*"); redisUtil.removePattern(getCacheKey(keysPattern)); } public int size() { if (keys() == null) return 0; return keys().size(); } public Set<K> keys() { Set<K> set = (Set<K>) redisUtil.getPatternKey("*"); return set; } public Collection<V> values() { List<V> result = new LinkedList<V>(); return result; } private String getCacheKey(Object key) { if (redisShiroCachePre == null || redisShiroCachePre.trim().length() == 0) return this.REDIS_SHIRO_CACHE + getName() + ":" + key; else return this.REDIS_SHIRO_CACHE + "-" + redisShiroCachePre + getName() + ":" + key; } }
<!-- 使用redis缓存管理器 --> <bean id="jedisShiroCacheManager" class="com.pandy.framework.base.shiro.cache.JedisShiroCacheManager"> <property name="redisUtil" ref="redisUtil" /> <property name="redisShiroCachePre" value="PANDY_WEB_APP_CACHE"/> </bean> <bean id="cacheManagerWrapper" class="com.pandy.framework.base.shiro.cache.CustomShiroCacheManager"> <property name="shiroCacheManager" ref="jedisShiroCacheManager" /> </bean>
RedisUtil.java参考: http://panyongzheng.iteye.com/blog/2295435
发表评论
-
分布式存储系统GlusterFS安装配置
2016-06-27 14:51 1038http://navyaijm.blog.51cto.com/ ... -
分布式查询 presto 入门安装使用
2016-06-24 15:44 2507http://my.oschina.net/chengxiao ... -
跟我学习dubbo
2016-06-17 15:20 1074跟我学习dubbo-目录 http://bluereader. ... -
JavaMelody监控web服务器
2016-06-17 14:20 1185JavaMelody监控web服务器 http://my.os ... -
freemarker使用记录
2016-06-08 16:24 1313freeMarker语法 http://uule.iteye. ... -
freemarker判断是否为空
2016-06-08 16:03 2http://www.oschina.net/code/sni ... -
ehcache 分布式支持
2016-06-05 22:26 1104原文 http://my.oschina.net/glenxu ... -
Intellij IDEA插件开发入门
2016-05-26 11:42 2889原文: http://blog.csdn.net/dc_726 ... -
阿里巴巴Druid数据源的配置与使用
2016-05-24 17:42 1551http://my.oschina.net/wjme/blog ... -
分布式任务调度组件 Uncode-Schedule
2016-05-13 14:47 2293http://www.oschina.net/p/uncode ... -
mysql中间件研究(Atlas,cobar,TDDL), 分库分表插件
2016-05-09 14:15 3457http://www.guokr.com/blog/47576 ... -
Fedora安装Redis
2016-05-04 08:56 1416管理工具: centos6.3下安装phpredisadmin ... -
redis-install.sh
2016-05-04 08:56 4#!/bin/bash # From here: http: ... -
redis 集群中Session解决方案之Spring Session
2016-05-04 08:54 1323集群中Session解决方案之Spring Session h ... -
使用Spring-data进行Redis操作
2016-05-04 08:54 4806使用Spring-data进行Redis操作 http://z ... -
spring 注解方式下使用commons-validator 验证表单
2016-05-03 11:08 3085原文: http://www.programgo.com/ar ... -
Apache Lucene 5.x版本 示例
2016-04-28 15:46 1151http://blog.csdn.net/isea533/ar ... -
Hessian 二进制RPC协议整合到SpringMVC
2016-04-27 09:47 1750SpringMVC集成Hessianhttp://blog.c ... -
shiro过滤器过滤属性含义
2016-04-21 13:51 1320http://my.oschina.net/cng1985/b ... -
Hadoop 2.6.4分布式集群环境搭建
2016-04-13 11:45 756http://my.oschina.net/jackieyea ...
相关推荐
该项目是一款基于freeRTOS操作系统和STM32F103x微控制器的手机远程控制浴室温度系统设计源码,共包含1087个文件,包括580个C语言源文件、269个头文件、45个汇编源文件、36个数据文件、36个目标文件、35个编译规则文件、28个包含文件、27个文本文件、6个源文件、3个归档文件。此系统通过手机远程实现对浴室温度的有效控制,适用于智能浴室环境管理。
labview程序代码参考学习使用,希望对你有所帮助。
labview程序代码参考学习使用,希望对你有所帮助。
labview程序代码参考学习使用,希望对你有所帮助。
labview程序代码参考学习使用,希望对你有所帮助。