在spring boot中sessioncokieconfig的默认设置值是什么,如何设置?

50pmv0ei  于 2021-06-30  发布在  Java
关注(0)|答案(0)|浏览(295)

我正在尝试配置我的自定义 DefaultCookieSerializer 在spring会话中,我要设置的唯一属性是 sameSite ,我希望所有其他设置都使用“default”值。所以我读了一些帖子,像这样
下面是一些代码片段:

@Bean
    public DefaultCookieSerializer cookieSerializer(){
        return new DefaultCookieSerializer();
    }

    private class CookieSerializerConfigure implements ServletContainerInitializer{
        @Override
        public void onStartup(Set<Class<?>> set, ServletContext servletContext) throws ServletException {
            SessionCookieConfig sessionCookieConfig = servletContext.getSessionCookieConfig();
            // about the setting, see:
            // https://docs.spring.io/spring-session/docs/current/api/org/springframework/session/web/http/DefaultCookieSerializer.html
            // https://github.com/spring-projects/spring-session/issues/87
            DefaultCookieSerializer cookieSerializer = cookieSerializer();
            cookieSerializer.setUseSecureCookie(sessionCookieConfig.isSecure());
            cookieSerializer.setUseHttpOnlyCookie(sessionCookieConfig.isHttpOnly());
            cookieSerializer.setCookiePath(sessionCookieConfig.getPath());
            cookieSerializer.setCookieName(sessionCookieConfig.getName());
            cookieSerializer.setCookieMaxAge(sessionCookieConfig.getMaxAge());
            cookieSerializer.setDomainName(sessionCookieConfig.getDomain());
        }
    }

如果我不在的实现中设置属性,这会起作用吗 ServletContainerInitializer ?
我知道在application.properties中有一些属性Map到 SessionCookieConfig 但是,字段的默认设置值是什么 SessionCookieConfig 如果我没有在application.properties中指定它,那么如何在spring引导应用程序中设置它?

server.servlet.session.cookie.max-age=something
server.servlet.session.cookie.name=something

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题