JdbcOperationsSessionRepository和SessionDestroyed不兼容

问题描述 投票:0回答:1

我正在使用spring引导,并且正在使用spring会话,其中spring在APP_SESSION表中创建一个会话并向其中添加行。它具有max_inactive_interval列,该列中具有几秒钟的值,在此之后会话超时。现在,我想在会话超时之前做一些事情。我想在不同的表上执行一些数据库操作并设置一个标志。

我为此使用了JdbcOperationsSessionRepository

    @Bean
@Order(1)
public JdbcOperationsSessionRepository sessionRepository(
    @Qualifier("springSessionJdbcOperations") JdbcOperations jdbcOperations,
    PlatformTransactionManager transactionManager) {
    JdbcOperationsSessionRepository repository = super.sessionRepository(jdbcOperations, transactionManager);
    repository.setDefaultMaxInactiveInterval(maxInactiveIntervalInSeconds);
    repository.setTableName(TABLE_NAME);
    return repository;
}

我已经尝试过此

@Bean                           // bean for http session listener
public HttpSessionListener aohttpSessionListener() {
    return new HttpSessionListener() {
        @Override
        public void sessionCreated(HttpSessionEvent session) {               // This method will be called when session created
            System.out.println("Session Created with session id+" + session.getSession().getId());
        }

        @Override
        public void sessionDestroyed(HttpSessionEvent session) {         // This method will be automatically called when session destroyed
            System.out.println("Session Destroyed, Session id:" + session.getSession().getId());
            // database operations
            }

        }
    };

但是根据此https://github.com/spring-projects/spring-session/issues/1082,我认为它不起作用

感谢您的帮助。预先感谢。

spring spring-boot spring-session httplistener
1个回答
0
投票

Spring Session JDBC不支持发布会话事件。只有Spring Session Redis支持。

Source code comment on line 68

© www.soinside.com 2019 - 2024. All rights reserved.