最近在应用了shiro的缓存,可以用encache,memcached,redies,用maven模块化进行切换。这样就可以按着实际需要,自由切换shiro缓存了。 今天看了一篇文章,觉得可以参考一下。 解决使用redis进行基于shiro的session集群共享,shiro+redis
<dependency>
<groupId>org.crazycake</groupId>
<artifactId>shiro-redis</artifactId>
<version>2.4.2.1-RELEASE</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.7.2</version>
</dependency>
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<property name="realm" ref="userRealm" />
<property name="sessionManager" ref="sessionManager" />
<property name="cacheManager" ref="cacheManager" />
</bean>
<!-- shiro redisManager -->
<bean id="redisManager" class="org.crazycake.shiro.RedisManager">
<property name="host" value="127.0.0.1" />
<property name="port" value="6379" />
<property name="expire" value="1800" />
<property name="timeout" value="180000" />
<property name="password" value="111111" />
</bean>
<!-- redisSessionDAO -->
<bean id="redisSessionDAO" class="org.crazycake.shiro.RedisSessionDAO">
<property name="redisManager" ref="redisManager" />
</bean>
<!-- sessionManager -->
<bean id="sessionManager"
class="org.apache.shiro.web.session.mgt.DefaultWebSessionManager">
<property name="sessionDAO" ref="redisSessionDAO" />
</bean>
<!-- cacheManager -->
<bean id="cacheManager" class="org.crazycake.shiro.RedisCacheManager">
<property name="redisManager" ref="redisManager" />
</bean>
<bean id="userRealm" class="cn.com.****.system.web.filter.UserRealm">
<property name="userAuthService" ref="userAuthService" />
<!-- 关闭shiro的默认缓存,自己解决 -->
<property name="authenticationCachingEnabled" value="false" />
<property name="authorizationCachingEnabled" value="false" />
</bean>
<bean id="userAuthService" class="cn.com.****.system.business.impl.UserBusImpl" />