1. 程式人生 > >SpringBoot+Shiro+SpringSession的簡單整合配置簡要步驟

SpringBoot+Shiro+SpringSession的簡單整合配置簡要步驟

1. 新增依賴的相關庫

<dependency>
    <groupId>org.springframework.session</groupId>
    <artifactId>spring-session</artifactId>
    <version>1.2.1.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>
spring-boot-starter-redis</artifactId> <version>1.3.3.RELEASE</version></dependency>

2. HttpSessionConfig.java

importorg.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
@EnableRedisHttpSession
public class HttpSessionConfig {
}

3. redis連線引數配置

spring:
  redis:
    host: localhost
    port: 6379
    password: secret

4. Shiro安全管理器配置

安全管理的sessionManager需要注入org.apache.shiro.web.mgt.DefaultWebSecurityManager

<bean id="servletContainerSessionManager" class="org.apache.shiro.web.session.mgt.ServletContainerSessionManager"/>
<!-- 安全管理器 -->
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager"> <property name="sessionManager" ref="servletContainerSessionManager"/> <property name="realm" ref="dataBaseRealm"/> <property name="cacheManager" ref="cacheManager"/> </bean>

5. 完成上述配置後,可以測試了