Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 如何配置自定义会话配置?_Spring Boot_Spring Mvc_Configuration - Fatal编程技术网

Spring boot 如何配置自定义会话配置?

Spring boot 如何配置自定义会话配置?,spring-boot,spring-mvc,configuration,Spring Boot,Spring Mvc,Configuration,我使用的是Springboot 5.1.5。 我想自定义如何在会话中存储信息,所以我添加了这个 public class MyCustomSessionAttributeStore extends DefaultSessionAttributeStore { @Override protected String getAttributeNameInSession(WebRequest request, String attributeName) { Objec

我使用的是Springboot 5.1.5。 我想自定义如何在会话中存储信息,所以我添加了这个

public class MyCustomSessionAttributeStore extends DefaultSessionAttributeStore {

    @Override
    protected String getAttributeNameInSession(WebRequest request, String attributeName) {

        Object handler = request.getAttribute("", WebRequest.SCOPE_REQUEST);
        if (handler == null) return super.getAttributeNameInSession(request, attributeName);

        return handler.getClass().getName() + "." + super.getAttributeNameInSession(request, attributeName);
    }
}


@Configuration
public class SessionConfiguration extends WebMvcConfigurationSupport {

    @Bean
    public SessionAttributeStore sessionAttributeStore() {
        return new MyCustomSessionAttributeStore();
    }

    @Override
    @Bean
    public RequestMappingHandlerAdapter requestMappingHandlerAdapter() {
        RequestMappingHandlerAdapter rmha = super.requestMappingHandlerAdapter();
        rmha.setSessionAttributeStore(sessionAttributeStore());
        return rmha;
    }

    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        super.configurePathMatch(configurer);

        configurer.setUseSuffixPatternMatch(false);
    }
}

(不要介意“对象处理程序”后面的代码-这仍然是一项正在进行的工作)

为了配置这个定制,我还添加了这个

public class MyCustomSessionAttributeStore extends DefaultSessionAttributeStore {

    @Override
    protected String getAttributeNameInSession(WebRequest request, String attributeName) {

        Object handler = request.getAttribute("", WebRequest.SCOPE_REQUEST);
        if (handler == null) return super.getAttributeNameInSession(request, attributeName);

        return handler.getClass().getName() + "." + super.getAttributeNameInSession(request, attributeName);
    }
}


@Configuration
public class SessionConfiguration extends WebMvcConfigurationSupport {

    @Bean
    public SessionAttributeStore sessionAttributeStore() {
        return new MyCustomSessionAttributeStore();
    }

    @Override
    @Bean
    public RequestMappingHandlerAdapter requestMappingHandlerAdapter() {
        RequestMappingHandlerAdapter rmha = super.requestMappingHandlerAdapter();
        rmha.setSessionAttributeStore(sessionAttributeStore());
        return rmha;
    }

    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        super.configurePathMatch(configurer);

        configurer.setUseSuffixPatternMatch(false);
    }
}

但是,当我运行应用程序时,它会给我以下错误

WebSocketReactiveAutoConfiguration:
      Did not match:
         - @ConditionalOnWebApplication did not find reactive web application classes (OnWebApplicationCondition)

(其他配置类也是如此。)

此外,即使应用程序正在运行,它似乎也不会加载css或javascript等静态资源


如有任何建议,将不胜感激。提前谢谢你

这不是一个错误,它是关于什么匹配什么不匹配的调试报告。要配置存储,最好使用
BeanPostProcessor
,并重新配置
RequestMappingHandlerAdapter
,而不是创建新的附加实例。