`

spring-session-redis配置实例

阅读更多

web.xml配置:

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">

  <display-name>XXXX</display-name>

 

<context-param>

  <param-name>defaultHtmlEscape</param-name>

  <param-value>true</param-value>

</context-param>

 

<!--

- Key of the system property that should specify the root directory of this

- web app. Applied by WebAppRootListener or Log4jConfigListener.

-->

<context-param>

<param-name>webAppRootKey</param-name>

<param-value>xxxx.root</param-value>

</context-param>

 

<!--

- Location of the Log4J config file, for initialization and refresh checks.

- Applied by Log4jConfigListener.

-->

<context-param>

<param-name>log4jConfigLocation</param-name>

<param-value>/WEB-INF/log4j.properties</param-value>

</context-param>

 

    <context-param>

        <param-name>contextConfigLocation</param-name>

        <param-value>

        /WEB-INF/spring/*.xml

        </param-value>

    </context-param>

 

    <servlet>

        <servlet-name>dispatcher</servlet-name>

        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

        <init-param>

        <param-name>contextConfigLocation</param-name>

        <param-value>/WEB-INF/spring/mvc/dispatcher-servlet.xml</param-value>

        </init-param>

        <multipart-config>

        <max-file-size>10000000</max-file-size>

        </multipart-config>

        <load-on-startup>1</load-on-startup>

    </servlet>

 

    <servlet-mapping>

        <servlet-name>dispatcher</servlet-name>

        <url-pattern>/</url-pattern>

    </servlet-mapping>

    

    <!-- spring session on redis -->

     <filter>

<filter-name>springSessionRepositoryFilter</filter-name>

<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>

</filter>

    <!-- spring session on redis end-->

<filter>

<filter-name>characterEncodingFilter</filter-name>

<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>

<init-param>

<param-name>encoding</param-name>

<param-value>UTF-8</param-value>

</init-param>

<init-param>

<param-name>forceEncoding</param-name>

<param-value>true</param-value>

</init-param>

</filter>

<filter>

<filter-name>SignonFilter</filter-name>

<filter-class>xxxx.xxx.SignonFilter</filter-class>

</filter>

 

<!-- spring session on redis -->

<filter-mapping>

<filter-name>springSessionRepositoryFilter</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

    <!-- spring session on redis over-->

 

<filter-mapping>

<filter-name>characterEncodingFilter</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping> 

<filter-mapping>

<filter-name>SignonFilter</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

 

<listener>

<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

</listener>

<!--

- Configures Log4J for this web app.

- As this context specifies a context-param "log4jConfigLocation", its file path

- is used to load the Log4J configuration, including periodic refresh checks.

-->

<listener>

<listener-class>

org.springframework.web.util.Log4jConfigListener

</listener-class>

</listener>

 

<servlet>

<servlet-name>xxServlet</servlet-name>

<servlet-class>xx.xx.xxServlet</servlet-class>

<init-param>

<param-name>xxxx</param-name>

<param-value>/WEB-INF/xxxx.properties</param-value>

</init-param>

<load-on-startup>99</load-on-startup>

</servlet>

 

 

<jsp-config>

<taglib>

<taglib-uri>/tags/xxxx</taglib-uri>

<taglib-location>/WEB-INF/tld/xxxx.tld</taglib-location>

</taglib>

</jsp-config>

 

</web-app>

 

spring session 配置:

redis主从模式,无分片

 

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:cache="http://www.springframework.org/schema/cache"

xmlns:p="http://www.springframework.org/schema/p"

xmlns:tx="http://www.springframework.org/schema/tx"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd

http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.2.xsd

http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">

 

<bean class="xxxx.SessionDestroyEventListener"/>

 

<context:annotation-config/>

<bean class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration"/>

 

<bean id="redisSentinelConfiguration" class="org.springframework.data.redis.connection.RedisSentinelConfiguration">

<property name="master">

            <bean class="org.springframework.data.redis.connection.RedisNode">

                <property name="name" value="mymaster"/>

            </bean>

        </property>

        <property name="sentinels">

            <set>

                <bean class="org.springframework.data.redis.connection.RedisNode">

                    <constructor-arg name="host" value="192.168.0.3"/> 

                    <constructor-arg name="port" value="26379"/>                   

                </bean>

                <bean class="org.springframework.data.redis.connection.RedisNode">

                    <constructor-arg name="host" value="192.168.0.3"/> 

                    <constructor-arg name="port" value="26380"/>                   

                </bean>

            </set>

        </property>

   </bean>

 

<bean class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">

<constructor-arg ref="redisSentinelConfiguration"/>

</bean>

 

</beans>

 

分享到:
评论

相关推荐

    spring-boot示例项目

    data-redis|[lettuce,redis,session redis,YAML配置,连接池,对象存储](https://github.com/smltq/spring-boot-demo/blob/master/data-redis/HELP.md) quartz|[Spring Scheduler,Quartz,分布式调度,集群,mysql持久化...

    SpringMVC-Mybatis-Shiro-redis-master 权限集成缓存中实例

    -- redis 配置,也可以把配置挪到properties配置文件中,再读取 --&gt; &lt;bean id="jedisPool" class="redis.clients.jedis.JedisPool"&gt; &lt;constructor-arg index="0" ref="jedisPoolConfig" /&gt; &lt;constructor-arg ...

    springmvc+shiro+spring+hibernate+redis缓存管理示例

    完整的spring +springmvc+hibernate+shiro项目实例,详细的shiro配置介绍,通过redis管理用户session缓存。。。。。。。。

    基于 redlock的java支持redis的唯一实现支持多实例集群的分布式锁

    支持多实例集群,分布式锁,spring cache 整合,session集群,消息队列,对象存储。redisson是java支持redis的redlock的唯一实现, 集成该项目后只需要极少的配置.就能够使用redisson的全部功能. 目前支持 集群模式,云托管...

    基于SpringMVC的一个web框架

    Excel工具类 Word工具类 Java NIO实现socket工具类 分布式session jdk升级到1.7 嵌入式redis服务(只支持linux) 1.0.13 修改默认的beanName生成策略,controller参数扩展 1.0.14 分布式session使用zookeeper 1.0.15 ...

    【JeeSpringCloud v3.2.4】后台权限管理系统+互联网云快速开发框架+微服务分布式代码生成

    模块包括:定时任务调度、服务器监控、平台监控、平台设置、开发平台、单点登录、Redis分布式高速缓存、会员、营销、在线用户、日志、在线人数、访问次数、调用次数、直接集群、接口文档、生成模块、代码实例、安装...

    Java思维导图xmind文件+导出图片

    session跨域共享及企业级单点登录解决方案实战 分布式事务解决方案实战 高并发下的服务降级、限流实战 基于分布式架构下分布式锁的解决方案实战 分布式架构实现分布式定时调度 分布式架构-中间件 分布式消息...

    【JeeSpringCloud v3.2.4】后台权限管理系统+互联网云快速开发框架+微服务分布式代码生成.zip

    模块包括:定时任务调度、服务器监控、平台监控、平台设置、开发平台、单点登录、Redis分布式高速缓存、会员、营销、在线用户、日志、在线人数、访问次数、调用次数、直接集群、接口文档、生成模块、代码实例、安装...

    JeeSpringCloud后台权限管理系统-其他

    模块包括:定时任务调度、服务器监控、平台监控、平台设置、开发平台、单点登录、Redis分布式高速缓存、会员、营销、在线用户、日志、在线人数、访问次数、调用次数、直接集群、接口文档、生成模块、代码实例、安装...

    JAVA上百实例源码以及开源项目源代码

     Java波浪文字,一个利用Java处理字符的实例,可以设置运动方向参数,显示文本的字符数组,高速文本颜色,显示字体的 FontMetrics对象,得到Graphics实例,得到Image实例,填充颜色数组数据,初始化颜色数组。...

    JAVA上百实例源码以及开源项目

     Java波浪文字,一个利用Java处理字符的实例,可以设置运动方向参数,显示文本的字符数组,高速文本颜色,显示字体的 FontMetrics对象,得到Graphics实例,得到Image实例,填充颜色数组数据,初始化颜色数组。...

    java开源包1

    jSIP这个Java包目标是用Java实现SIP(SIP:Session Initiation Protocol)协议及SIP协议的其它扩展部 分。 Java表达式语法解析库 parboiled parboiled 是一个纯Java库提供了一种轻量级,易于使用,功能强大和优雅的PEG...

    java开源包10

    jSIP这个Java包目标是用Java实现SIP(SIP:Session Initiation Protocol)协议及SIP协议的其它扩展部 分。 Java表达式语法解析库 parboiled parboiled 是一个纯Java库提供了一种轻量级,易于使用,功能强大和优雅的PEG...

    java开源包2

    jSIP这个Java包目标是用Java实现SIP(SIP:Session Initiation Protocol)协议及SIP协议的其它扩展部 分。 Java表达式语法解析库 parboiled parboiled 是一个纯Java库提供了一种轻量级,易于使用,功能强大和优雅的PEG...

    java开源包3

    jSIP这个Java包目标是用Java实现SIP(SIP:Session Initiation Protocol)协议及SIP协议的其它扩展部 分。 Java表达式语法解析库 parboiled parboiled 是一个纯Java库提供了一种轻量级,易于使用,功能强大和优雅的PEG...

    java开源包6

    jSIP这个Java包目标是用Java实现SIP(SIP:Session Initiation Protocol)协议及SIP协议的其它扩展部 分。 Java表达式语法解析库 parboiled parboiled 是一个纯Java库提供了一种轻量级,易于使用,功能强大和优雅的PEG...

    java开源包5

    jSIP这个Java包目标是用Java实现SIP(SIP:Session Initiation Protocol)协议及SIP协议的其它扩展部 分。 Java表达式语法解析库 parboiled parboiled 是一个纯Java库提供了一种轻量级,易于使用,功能强大和优雅的PEG...

    java开源包8

    jSIP这个Java包目标是用Java实现SIP(SIP:Session Initiation Protocol)协议及SIP协议的其它扩展部 分。 Java表达式语法解析库 parboiled parboiled 是一个纯Java库提供了一种轻量级,易于使用,功能强大和优雅的PEG...

    java开源包11

    jSIP这个Java包目标是用Java实现SIP(SIP:Session Initiation Protocol)协议及SIP协议的其它扩展部 分。 Java表达式语法解析库 parboiled parboiled 是一个纯Java库提供了一种轻量级,易于使用,功能强大和优雅的PEG...

Global site tag (gtag.js) - Google Analytics