HTTP Session Repository

  • Released
  • Version
  • Authors
  • Link


Microservice http-session-repository moves your http sessions to external microservice. This way for example when you restart your microservices which are using servlet container your sessions will be sustained.


Just upload microservice zip ( to JLupin Platform. To do so put microservice zip inside upload directory in your platform directory. Then upload it to server with command microservice upload and that’s all.


Inside your web app microservice put http-session-repository-plugin with spring-session as a



Then enable remote sessions by adding below annotation to your Spring configuration file. It is very important to add this properly or remote sessions won't work.


Also make sure that JLupinDelegator bean is defined in your configuration (definition must be uniquue for @Autowired annotation so make sure you defined only one bean of this type or mark one definition as @Primary).

Example configuration:

public class TestServletSpringConfiguration {
    public JLupinDelegator getJLupinDelegator() {
        return JLupinClientUtil.generateInnerMicroserviceLoadBalancerDelegator(PortType.JLRMC);

Adding this component scan annotation provides JLupin's SessionRepository bean which is used by Spring Boot for managing http sessions.

Description how Spring HTTP Session works: here.


You can change your sessions max inactive interval by setting property "jlupin.http.seesion.repository.maxInactiveInterval" to number of seconds you want in your microservice.

You can also change interval time which is used by http-session-repository to check for expired sessions to remove them from memory. To do so set property "session.repository.check.rate" to number of milliseconds you want. By default this interval is set to 5 minutes.

How to access HTTP Session object in your code?

A few examples are shown below.

1. Autowire HttpSession in your controller.

public class IndexController {
    private HttpSession httpSession;
    // controller's methods

2. Autowire HttpSession as controller method argument:

public class IndexController {
    public String example(@Autowired HttpSession httpSession) {
        // method body

3. In plain servlet get it from HttpServletRequest object.

@WebServlet(urlPatterns = "/example")
public class ExampleServlet extends HttpServlet {
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        final HttpSession session = req.getSession();
        // method body

You can see example application on our github: link.

That’s all. From now all your sessions will be handled by remote bean (also sessions used by plain servlets!).


No comments found.