0

A code snippet for a specific case

@Configuration
@NewEnableRedisHttpSession(maxInactiveIntervalInSeconds = 900)
@Import({RedisConfiguration.class})

Here is a annotation value: maxInactiveIntervalInSeconds = 900

@NewEnableRedisHttpSession(maxInactiveIntervalInSeconds = 900)

I want to configure it like

@NewEnableRedisHttpSession("${maxInactiveIntervalInSeconds}")

some configuration file will give the value maxInactiveIntervalInSeconds = 900

Vy Do
  • 46,709
  • 59
  • 215
  • 313
wo4wangle
  • 99
  • 6

1 Answers1

1

use

@EnableRedisHttpSession(maxInactiveIntervalInSeconds = intervalInSeconds)

more specific for your need

@EnableRedisHttpSession(maxInactiveIntervalInSeconds = 900)

default value is 1800 .

See https://docs.spring.io/spring-session/docs/current/api/index.html?org/springframework/session/data/redis/config/annotation/web/http/EnableRedisHttpSession.html section maxInactiveIntervalInSeconds .

Supplement based on comment. Do like this, in case you want get value from application.properties

spring.session.timeout=9000
@Value("${spring.session.timeout}")
private Integer maxInactiveIntervalInSeconds;

see https://stackoverflow.com/a/37440818/3728901

Vy Do
  • 46,709
  • 59
  • 215
  • 313
  • Thanks for you reply! Does`@EnableRedisHttpSession(maxInactiveIntervalInSeconds = intervalInSeconds)` means I can set intervalInSeconds in configuration file ? I know I can give a value to `maxInactiveIntervalInSeconds`, but what I need is to set the value in **configuration file**. – wo4wangle Nov 17 '21 at 07:33
  • Yes, you can set value in `application.properties` or another `*.properties` file. See more in my edited answer. – Vy Do Nov 17 '21 at 07:58
  • Cool, I will have a try. – wo4wangle Nov 17 '21 at 08:05
  • You can set key as another string, for example `spring.session.timeoutFooBar=900` , `spring.session.timeoutFooBarZuu=1900` ; then change accordingly at `@Value("${spring.session.timeoutFooBarZuu}")` – Vy Do Nov 17 '21 at 08:11
  • Seems work, you save my days!Thanks – wo4wangle Nov 18 '21 at 01:51