Commit d2133687 authored by Phillip Webb's avatar Phillip Webb

Use persistent servlet session with DevTools

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

Fixes gh-3530
parent 08d1f6da
......@@ -46,6 +46,7 @@ class DevToolsPropertyDefaultsPostProcessor implements BeanFactoryPostProcessor,
properties.put("spring.groovy.template.cache", "false");
properties.put("spring.velocity.cache", "false");
properties.put("spring.mustache.cache", "false");
properties.put("server.session.persistent", "true");
PROPERTIES = Collections.unmodifiableMap(properties);
}
......
......@@ -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);
}
}
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment