gpt4 book ai didi

java - 避免在 Spring 中创建 session

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:58:38 27 4
gpt4 key购买 nike

我有一个 Spring Web 应用程序,它在每个请求上创建一个 session ,我想避免这种情况。

我有这样的配置:

<security:http pattern="/**" auto-config='true' create-session="never" use-expressions="true">
<security:intercept-url pattern="/**" access="permitAll" />
</security:http>

<security:authentication-manager>
<security:authentication-provider>
<security:jdbc-user-service data-source-ref="dataSource"/>
</security:authentication-provider>
</security:authentication-manager>

然后我调用 Controller

@RequestMapping(method=RequestMethod.GET, value="/experiences", produces="application/json")
public String getExperiencesList(
HttpServletRequest request,
@RequestParam(value = "channel",required=true) String channel,
@RequestParam(value = "page",required=true) int page,
Model model) {
String path = "http://" + HOST + request.getContextPath();
model.addAttribute("json", experienceService.getExperiencesList(page,channel,path));

return "json";
}

这将通过移动应用程序使用,同一个应用程序可以打开无限 session ,知道如何避免这种情况吗?

谢谢。

最佳答案

好的,完成了,我重构了安全性并添加了一些更改。

在其他文件中添加安全配置:

<http pattern="/**" security="none" create-session="never"/>

在 web.xml 中:

<http create-session="never"></http>

并在jsp页面添加session="false"。

现在似乎工作正常。

关于java - 避免在 Spring 中创建 session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31243984/

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