【发布时间】:2020-02-18 16:58:31
【问题描述】:
我有以下 Spring Session 代码:
@Bean
public LettuceConnectionFactory connectionFactory() {
String hostName = AcmeProperty.getProperty("spring.redis.host", "localhost");
int port = Integer.parseInt(AcmeProperty.getProperty("spring.redis.port", "6379"));
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration(hostName, port);
return new LettuceConnectionFactory(redisStandaloneConfiguration);
}
当我在本地运行 redis 时,它可以很好地使用以下设置:
spring.redis.host=localhost
spring.redis.port=6379
但是,当我通过以下设置使用 Azure Cache for Redis 时:
spring.redis.host=acmedev.redis.cache.windows.net
spring.redis.port=6380
我收到此警告,应用程序挂起:
WARN (org.springframework.session.config.annotation.web.http.SpringHttpSessionConfiguration:166) || - Unable to obtain SessionCookieConfig: Section 4.4 of the Servlet 3.0 specification does not permit this method to be called from a ServletContextListener that was not defined in web.xml, a web-fragment.xml file nor annotated with @WebListener
我需要进行哪些更改才能使其与 Azure Cache for Redis 一起使用?
我试过this code,但同样的事情发生了:
@Bean
public JedisConnectionFactory connectionFactory() {
String hostName = AcmeProperty.getProperty("spring.redis.host", "localhost");
int port = Integer.parseInt(AcmeProperty.getProperty("spring.redis.port", "6379"));
String password = AcmeProperty.getProperty("spring.redis.password");
SSLSocketFactory sslSocketFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
SSLParameters sslParameters = new SSLParameters();
sslParameters.setEndpointIdentificationAlgorithm("HTTPS");
sslParameters.setProtocols(new String[]{"TLSv1.2"});
String uriStr = String.format("rediss://%s:%s", hostName, port);
URI uri = URI.create(uriStr);
JedisShardInfo shardInfo = new JedisShardInfo(uri, sslSocketFactory, sslParameters, null);
shardInfo.setPassword(password);
return new JedisConnectionFactory(shardInfo);
}
【问题讨论】:
标签: spring-session lettuce azure-redis-cache