Use persistent servlet session with DevTools

Set `server.session.persistent=true` when running DevTools to ensure
persistent sessions are used.

Fixes gh-3530
This commit is contained in:
Phillip Webb
2015-07-16 17:27:31 -07:00
parent 08d1f6daf5
commit d2133687b0
3 changed files with 16 additions and 4 deletions

View File

@@ -16,6 +16,10 @@
package sample.devtools;
import java.util.Date;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -25,10 +29,15 @@ import org.springframework.web.servlet.ModelAndView;
public class MyController {
@RequestMapping("/")
public ModelAndView get() {
ModelMap model = new ModelMap("message", Message.MESSAGE);
public ModelAndView get(HttpSession session) {
Object sessionVar = session.getAttribute("var");
if (sessionVar == null) {
sessionVar = new Date();
session.setAttribute("var", sessionVar);
}
ModelMap model = new ModelMap("message", Message.MESSAGE).addAttribute(
"sessionVar", sessionVar);
return new ModelAndView("hello", model);
}
}

View File

@@ -7,7 +7,9 @@
</head>
<body>
<h1 layout:fragment="header" th:text="${message}">Header</h1>
<div layout:fragment="content">Lorem ipsum dolor sit amet,
<div layout:fragment="content">
<h2 th:text="${sessionVar}">Session Var</h2>
Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Cras ut fringilla augue, quis dictum
turpis. Sed tincidunt mi vel euismod viverra. Nulla facilisi.
Suspendisse mauris dolor, egestas ac leo at, porttitor ullamcorper