我遇到了Spring和@EnableRedisHttpSession这个奇怪的问题
如果我使用这个设置,一切都是正确的:
@Configuration
@Profile({"prod"})
@EnableRedisHttpSession
public class SecurityConfiguration extends WebSecurityConfigurerAdapter 在除WebSecurity之外的其他配置文件中运行时,不会初始化RedisSession和prod。
另一方面,如果我使用“否定式”配置文件,则安全逻辑和redis逻辑都会初始化:
@Configuration
@Profile({"!dev", "!test"})
@EnableRedisHttpSession
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {我正在这样做,因为我想运行使用自定义配置文件从外部。
我尝试过几种解决办法:
security.ignored: /**禁用了它spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.session.SessionAutoConfiguration
这也是:spring.data.redis.repositories.enabled=false,但没有成功。我正在运行SpringBootv1.5.16. running
编辑:这是初始化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发布于 2019-03-05 09:56:45
我已经很久没有做Spring了,但是我确实找到了这个答案,这表明你不能“否定”概要:Can I negate (!) a collection of spring profiles?
https://stackoverflow.com/questions/54999690
复制相似问题