2017-10-03 16 views
3

セッションストアとしてredisを使用してスプリングセッションを設定しました。負荷が大きくなると、結果的にユーザーはランダムなセッションデータを取得することになります。スプリングセッションとセッションの再分割

残念ながら、再現することはできず、テスト環境では再現できません。

誰も似たような経験をしており、見ている方向を指すことができますか?

+0

我々は、我々のアプリケーションで似問題に遭遇し、あなたが見つけました原因/解決策? – Tim

答えて

1

次のように私のプロジェクトでredisセッションストアを使用している春のセッションを使用しています、それは正常に動作します、私はそれを共有する、それは助けて欲しい!

使用春のブートスターターバージョン:1.4.3

<dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-security</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-configuration-processor</artifactId> 
     <optional>true</optional> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.session</groupId> 
     <artifactId>spring-session</artifactId> 
    </dependency> 


    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-data-redis</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.security</groupId> 
     <artifactId>spring-security-core</artifactId> 
     <version>4.2.0.RELEASE</version> 
    </dependency> 

    <dependency> 
     <groupId>biz.paluch.redis</groupId> 
     <artifactId>lettuce</artifactId> 
     <version>3.5.0.Final</version> 
    </dependency> 

春セッションRedisの構成クラス:

package az.com.cybernet.aas.config; 

import org.springframework.beans.factory.annotation.Value; 
import org.springframework.context.annotation.Bean; 
import org.springframework.data.redis.connection.lettuce. 
LettuceConnectionFactory; 
import org.springframework.session.data.redis.config.annotation.web.http. 
EnableRedisHt 
tpSession; 
import org.springframework.session.web.http.CookieHttpSessionStrategy; 
import org.springframework.session.web.http.CookieSerializer; 
import org.springframework.session.web.http.DefaultCookieSerializer; 
import org.springframework.session.web.http.HttpSessionStrategy; 



@EnableRedisHttpSession 
public class RedisConfig { 

@Value("${spring.redis.host}") 
private String hostname; 
@Value("${spring.redis.port}") 
private String port; 
// @Value("${spring.redis.password}") 
// private String password; 

@Bean 
public LettuceConnectionFactory connectionFactory() { 
    LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(); 
    connectionFactory.setHostName(hostname); 
    // connectionFactory.setPassword(password); 
    connectionFactory.setDatabase(2); 
    connectionFactory.setPort(Integer.parseInt(port)); 
    return connectionFactory; 
} 

@Bean 
public CookieSerializer cookieSerializer() { 
    DefaultCookieSerializer serializer = new DefaultCookieSerializer(); 
    serializer.setCookieName("JSESSIONID"); 
    serializer.setCookiePath("/"); 
    serializer.setDomainNamePattern("^.+?\\.(\\w+\\.[a-z]+)$"); 
    return serializer; 
} 

@Bean 
public HttpSessionStrategy strategy() { 
    CookieHttpSessionStrategy cookieHttpSessionStrategy = new CookieHttpSessionStrategy(); 

    cookieHttpSessionStrategy.setCookieSerializer(cookieSerializer()); 
    return cookieHttpSessionStrategy; 

} 

}

関連する問題