解决使用redis进行基于shiro的session集群共享,shiro+redis

说明:无需写一行代码,直接配置就可以无缝衔接当前的shiro项目。

步骤一,pom配置:

       

<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>
步骤二,shiro的配置文件的修改

	<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" />



展开阅读全文

没有更多推荐了,返回首页