Disable HTTPSession for stateless web services [duplicate]

丶灬走出姿态 提交于 2019-12-13 09:37:35

问题


I would like to know if it is possible to disable the HTTPSession for an application server handling only web services RESTful.

I don't know if there are specific application servers or servlet containers designed to handle micro RESTful web services.

I think that disabling completely the session concept will give the following advantages:

  • Better performances
  • No risk to save data in the session breaking the concept of stateless of a RESTful webservice
  • Less classes loaded by the classloader
  • No unused information is saved in the session (for example the session id, session state)
  • less access to synchronized blocks (I think that at least in the Session the value of lastAccessedTime is updated for every request and this should be done in a synchronized block)

If there is no application server or servlet container that can do that: Is there any other Java engine that can handle micro services without creating something similar to an HttpSession?


回答1:


You cannot disable HttpSession on a servlet container, like Tomcat.

Maybe Play framework would be a good approach for implementing your design.




回答2:


You can't completely disable the HttpSession.

But you can ensure a HttpSession won't be created in your application. To do it, ensure the following methods are not being invoked (by yourself or by the frameworks you are using):

  • HttpServletRequest.getSession()
  • HttpServletRequest.getSession(boolean) with true

Microservices is an architecture design principle. If you want to use Spring, there's a guide you can follow.



来源:https://stackoverflow.com/questions/34673836/disable-httpsession-for-stateless-web-services

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!