Spring-Boot:@EnableRedisHttpSession注释会忽略配置文件(否定配置文件时)

时间:2019-03-05 09:41:04

标签: spring spring-boot

我正在使用Spring Boot Profiles和@EnableRedisHttpSession遇到这个奇怪的问题:

如果我使用此设置,则一切正确:

@Configuration
@Profile({"prod"})
@EnableRedisHttpSession
public class SecurityConfiguration extends WebSecurityConfigurerAdapter 

WebSecurity以外的其他配置文件中运行时,RedisSessionprod都不会初始化。

另一方面,如果我使用“否定”配置文件,则安全性和redis逻辑都会被初始化:

@Configuration
@Profile({"!dev", "!test"})
@EnableRedisHttpSession
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

我正在这样做,因为我想使用外部提供的自定义配置文件来运行。

我尝试了几种解决方法:

  • 出于安全性考虑,我已使用以下属性禁用了它:security.ignored: /**
  • 但是,我无法禁用Redis会话。我已经试过了: spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.session.SessionAutoConfiguration

    这也是:spring.data.redis.repositories.enabled=false,但没有成功。

我正在运行Spring-Boot v1.5.16.RELEASE

编辑:这是初始化Redis时显示的堆栈跟踪(此配置文件中不需要):

Caused by: org.springframework.data.redis.RedisConnectionFailureException:     Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
    at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.fetchJedisConnector(JedisConnectionFactory.java:204) ~[spring-data-redis-1.8.13.RELEASE.jar:na]
    at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.getConnection(JedisConnectionFactory.java:348) ~[spring-data-redis-1.8.13.RELEASE.jar:na]
    at org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration$EnableRedisKeyspaceNotificationsInitializer.afterPropertiesSet(RedisHttpSessionConfiguration.java:249) ~[spring-session-1.3.3.RELEASE.jar:na]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1692) ~[spring-beans-4.3.18.RELEASE.jar:4.3.18.RELEASE]
    at org.springframework.beans.fa

1 个答案:

答案 0 :(得分:1)

我还没有永远做过Spring,但是我确实找到了这个答案,表明您不能“否定”配置文件:https://www.scylladb.com/2017/11/30/mutant-monitoring-system-day-1/

相关问题