• Spring Boot: remove jsessionid from url


    参考代码 :Spring Boot: remove jsessionid from url

    我的SpringBoot用2.0.*,答案中的第一二个方案亲测无效。

    应该在继承了Configuration里面加入第三种方案所示的代码

    @Configuration
    //WebMvcConfigurerAdapter在2.0.*中已作废,有WebMvcConfigurer,WebMvcConfigurationSupport两种方案。
    //public class WebSecurityConfig extends WebMvcConfigurerAdapter{
    public class WebSecurityConfig implements WebMvcConfigurer {
    //public class WebSecurityConfig extends WebMvcConfigurationSupport {
                @Bean
                public ServletContextInitializer servletContextInitializer() {
                    return new ServletContextInitializer() {
    
                        @Override
                        public void onStartup(ServletContext servletContext) throws ServletException {
                           servletContext.setSessionTrackingModes(Collections.singleton(SessionTrackingMode.COOKIE));
                           SessionCookieConfig sessionCookieConfig=servletContext.getSessionCookieConfig();
                           sessionCookieConfig.setHttpOnly(true);
                        }
                    };
    
            }
    
    }

    或者

    @Configuration
    //WebMvcConfigurerAdapter在2.0.*中已作废,有WebMvcConfigurer,WebMvcConfigurationSupport两种方案。
    //public class WebSecurityConfig extends WebMvcConfigurerAdapter{
    public class WebSecurityConfig implements WebMvcConfigurer {
    //public class WebSecurityConfig extends WebMvcConfigurationSupport {
    
        @Bean
        public ServletContextInitializer servletContextInitializer() {
            return servletContext -> {
                servletContext.setSessionTrackingModes(Collections.singleton(SessionTrackingMode.COOKIE));
                SessionCookieConfig sessionCookieConfig=servletContext.getSessionCookieConfig();
                sessionCookieConfig.setHttpOnly(true);
            };
    
        }
    }

    可以看到该段代码实现了以下接口

    package org.springframework.boot.web.servlet;
    
    import javax.servlet.ServletContext;
    import javax.servlet.ServletException;
    
    @FunctionalInterface
    public interface ServletContextInitializer {
        void onStartup(ServletContext servletContext) throws ServletException;
    }
  • 相关阅读:
    Autowired注解原理
    postgresql 网页访问
    halconregion_to_bin将区域转换为二值图像
    halconboundary提取边界
    halcon文件操作
    halconset_color设置输出颜色
    halconinvert_matrix返回逆矩阵
    halconsub_image图像相减
    halconoverpaint_region用指定颜色填充指定区域
    halconfill_up填充区域
  • 原文地址:https://www.cnblogs.com/huanghongbo/p/8919926.html
Copyright © 2020-2023  润新知