简体   繁体   English

如何从springSessionRepositoryFilter中排除资源?

[英]How to exclude resources from springSessionRepositoryFilter?

We are trying to convert a legacy project to a more modern one. 我们正在尝试将旧项目转换为更现代的项目。 It was a servlet based application with jsp's, and we are moving towards Spring. 这是一个带有jsp的基于servlet的应用程序,我们正朝着Spring迈进。 We serve jsp-s, and they include many static resources. 我们为jsp-s服务,它们包含许多静态资源。 We are using Redis as session store, and it's mapped like a filter: 我们正在使用Redis作为会话存储,它的映射就像一个过滤器:

<filter>
    <filter-name>springSessionRepositoryFilter</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
    <filter-name>springSessionRepositoryFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

... ...

@Configuration
@EnableRedisHttpSession(maxInactiveIntervalInSeconds = SpringSessionConfig.MAX_INACTIVE_INTERVAL_IN_SECONDS)
@PropertySource(value = "classpath:redis.properties")
public class SpringSessionConfig { ... }

Static resources are spread in many different directories, and the problem is that, this filter runs for each and every resource, which is totally understandable. 静态资源分布在许多不同的目录中,问题在于,此过滤器针对每种资源运行,这是完全可以理解的。

Is there a smart way to exclude resources from this url pattern? 有没有从此网址格式中排除资源的聪明方法? Or some configuration for this RepositoryFilter? 还是此RepositoryFilter的一些配置?

The only solution I came up with, is to do a big refactor, and make proper namespaces for static resources, but right now, that's too much effort. 我想到的唯一解决方案是进行大量的重构,并为静态资源创建适当的名称空间,但是现在,这已经太费力了。

I also added resource handlers to Spring configuration, but it's ignored here. 我还在Spring配置中添加了资源处理程序,但是这里忽略了它。

我认为您可以扩展springSessionRepositoryFilter来实现自己的过滤器,然后在doFilterInternal方法中doFilterInternal排除资源,并配置springSessionRepositoryFilter bean手册而不是EnableRedisHttpSession批注,然后将过滤器bean名称配置为web.xml。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM