首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring:@EnableRedisHttpSession注释忽略配置文件(当它们被否定时)

Spring:@EnableRedisHttpSession注释忽略配置文件(当它们被否定时)
EN

Stack Overflow用户
提问于 2019-03-05 09:41:03
回答 1查看 808关注 0票数 0

我遇到了Spring和@EnableRedisHttpSession这个奇怪的问题

如果我使用这个设置,一切都是正确的:

代码语言:javascript
复制
@Configuration
@Profile({"prod"})
@EnableRedisHttpSession
public class SecurityConfiguration extends WebSecurityConfigurerAdapter 

在除WebSecurity之外的其他配置文件中运行时,不会初始化RedisSessionprod

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

代码语言:javascript
复制
@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,但没有成功。

我正在运行SpringBootv1.5.16. running

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

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2019-03-05 09:56:45

我已经很久没有做Spring了,但是我确实找到了这个答案,这表明你不能“否定”概要:Can I negate (!) a collection of spring profiles?

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54999690

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档