gpt4 book ai didi

java - 如何从 springSessionRepositoryFilter 中排除资源?

转载 作者:IT王子 更新时间:2023-10-29 06:07:31 25 4
gpt4 key购买 nike

我们正在尝试将遗留项目转换为更现代的项目。这是一个带有 jsp 的基于 servlet 的应用程序,我们正在转向 Spring。我们服务于jsp-s,它们包括很多静态资源。我们使用 Redis 作为 session 存储,它的映射就像一个过滤器:

<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 { ... }

静态资源分布在许多不同的目录中,问题是,这个过滤器针对每个资源运行,这是完全可以理解的。

有没有一种聪明的方法可以从这个 url 模式中排除资源?或者这个 RepositoryFilter 的一些配置?

我想出的唯一解决方案是进行大规模重构,并为静态资源创建适当的命名空间,但现在,这太费力了。

我还在 Spring 配置中添加了资源处理程序,但这里忽略了它。

最佳答案

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

关于java - 如何从 springSessionRepositoryFilter 中排除资源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41635354/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com