2015-07-06 56 views
2

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

我有这样的配置:

<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> 

我呼吁控制器

@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"; 
} 

这将通过移动应用程序使用,同一应用程序可以打开无限的会议,任何想法我怎么能避免这种情况?

谢谢。

+0

为什么你想避免创建会话?是的,有一个不需要的会话确实会造成一些开销,但会话实际上会导致什么问题? –

+0

根据上述配置,您的应用程序创建会话,Spring Security将使用它。 – Selva

+0

我们正在制作移动应用程序,并且此服务用于获取事件列表,如果每个移动设备创建会话都会对服务器造成问题。 – Magec

回答

1

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

添加其他文件中的安全配置与此:

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

在web.xml:

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

而添加的会话JSP页面上= “假”。

它现在似乎工作正常。