基于redis的spring-session共享

分布式、多节点部署是当保证项目稳定运行的一个选择,那么问题来了,集群部署时一般会用到负载均衡,这就涉及到了session共享问题。用户的每次请求可能访问的服务器都不一样,服务器间共享session,用户只需登录一次即可,对用户来说好像就是一台服务器。

解决方案有不少,springSession结合redis是一种最佳的选择之一。这种方案不依赖与web服务器的版本,任何版本的web服务器均可支持。不多说,给出简要配置。

官方给出了java和xml两种配置,这里只给出xml配置。

1、maven依赖


      org.springframework.session
      spring-session-data-redis
      1.3.3.RELEASE

 

2、 src/main/webapp/WEB-INF/spring/spring-session.xml

  
  
  
    
    
    	
    

     
  
      
        
          
          
          
          
          
         
      
      
     
           
           
                    
           
           
                    
           
     

3、src/main/webapp/WEB-INF/web.xml


    contextConfigLocation
    
        /WEB-INF/spring/*.xml
    


    
        org.springframework.web.context.ContextLoaderListener
    

    springSessionRepositoryFilter
    org.springframework.web.filter.DelegatingFilterProxy


    springSessionRepositoryFilter
    /*
    REQUEST
    ERROR

 

参考https://docs.spring.io/spring-session/docs/1.3.3.RELEASE/reference/html5/

 

 

你可能感兴趣的:(SpringMVC,Redis)