We have 2 spring-boot(3.3.0) application
web-application
- N instances
- each of them are scheduled spring-session(jdbc) cleanup-cron job every minutes (relying to
spring.session.jdbc.cleanup-cron
)
scheduler-application
- 1 instance
- not web application (
spring.main.web-application-type=none
)
these applications connect to same database.
When we change to disable cleanup-cron on web-application and to enable cleanup-cron on scheduler-application, but JdbcIndexedSessionRepository
was not created.
Because SessionAutoConfiguration
is annotated @ConditionalOnWebApplication
and not autoconfigured.
How can initialize JdbcIndexedSessionRepository
at spring.main.web-application-type=none
environment?
Current work-around is
- to add
spring-boot-starter-web
to dependencies and works as web-application. - to add
spring.main.lazy-initialization=false
becauseJdbcIndexedSessionRepository#afterPropertiesSet
never called and cron not scheduled.
scheduler-application
build.gradle
implementation("org.springframework.session:spring-session-jdbc")
+ implementation("org.springframework.boot:spring-boot-starter-web")
application.properties
+ spring.main.lazy-initialization=false
spring.session.store-type=jdbc
spring.session.timeout=24h
spring.session.jdbc.initialize-schema: never