2015-07-06 78 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頁面上= 「假」。

它現在似乎工作正常。