springboot加@EnableRedisHttpSession注解后namespace配置失效
程序员文章站
2022-04-15 18:56:47
配置和注解是配置的两种方式,加注解后,``` public void setRedisNamespace(String namespace) { this.redisNamespace = namespace; }```该方法得不到调用,不加注解则SpringBootRedisHttpSessionConfiguration类```//// Source code recreated from a .class file by IntelliJ IDEA......
配置和注解是配置的两种方式,加注解后,
public void setRedisNamespace(String namespace) {
this.redisNamespace = namespace;
}
该方法得不到调用,不加注解则SpringBootRedisHttpSessionConfiguration类
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package org.springframework.boot.autoconfigure.session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.session.SessionProperties.Redis;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.session.SessionRepository;
import org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration;
@Configuration
@ConditionalOnClass({RedisTemplate.class})
@ConditionalOnMissingBean({SessionRepository.class})
@ConditionalOnBean({RedisConnectionFactory.class})
@Conditional({SessionCondition.class})
class RedisSessionConfiguration {
RedisSessionConfiguration() {
}
@Configuration
public static class SpringBootRedisHttpSessionConfiguration extends RedisHttpSessionConfiguration {
public SpringBootRedisHttpSessionConfiguration() {
}
@Autowired
public void customize(SessionProperties sessionProperties) {
Integer timeout = sessionProperties.getTimeout();
if (timeout != null) {
this.setMaxInactiveIntervalInSeconds(timeout);
}
Redis redis = sessionProperties.getRedis();
this.setRedisNamespace(redis.getNamespace());
this.setRedisFlushMode(redis.getFlushMode());
}
}
}
会触发setRedisNamespace,当符合上面几个condition的时候会触发,如果加注解,则上面的
RedisOperationsSessionRepository会import,所以不满足
@ConditionalOnMissingBean({SessionRepository.class})
条件,不会触发自定义操作,加注解只能在注解里面加
本文地址:https://blog.csdn.net/wocan23/article/details/109642213