美文网首页
@EnableSpringHttpSession注解,使用spr

@EnableSpringHttpSession注解,使用spr

作者: 墨色尘埃 | 来源:发表于2019-11-21 18:15 被阅读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;
    }

相关文章

网友评论

      本文标题:@EnableSpringHttpSession注解,使用spr

      本文链接:https://www.haomeiwen.com/subject/jcotwctx.html