@EnableSpringHttpSession注解,使用spr

2019-11-21  本文已影响0人  墨色尘埃

1.使用spring封装实现的session:
@EnableSpringHttpSession
如果这里使用了@EnableSpringHttpSession注解,说明使用了SpringSession,
① 需要注入 SessionRepository

image.png

② pom中加入session的依赖包

image.png

在浏览器中默认的sessionid名是”SESSION”


image.png

进入@EnableSpringHttpSession注解

image.png

进入SpringHttpSessionConfiguration类
发现该类中没有注入sessionRepository类,所以需要在外部配置类中手动添加

    // TODO: 2019/11/21  由于使用了springhttpsession,所以需要实现repository
    /**
     * 由于使用了springhttpsession,所以需要实现repository
     * 如果使用了Redis,不需要使用这个
     * @return
     */
    @Bean
    public SessionRepository sessionRepository() {
        SessionRepository mapSessionRepository = new MapSessionRepository();
//        mapSessionRepository.setDefaultMaxInactiveInterval(60);
        return mapSessionRepository;
    }
上一篇 下一篇

猜你喜欢

热点阅读