diff --git a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsPropertyDefaultsPostProcessor.java b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsPropertyDefaultsPostProcessor.java index fe20ea90e7..45815b8221 100644 --- a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsPropertyDefaultsPostProcessor.java +++ b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsPropertyDefaultsPostProcessor.java @@ -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); } diff --git a/spring-boot-samples/spring-boot-sample-devtools/src/main/java/sample/devtools/MyController.java b/spring-boot-samples/spring-boot-sample-devtools/src/main/java/sample/devtools/MyController.java index f9ccbe258a..7620751152 100644 --- a/spring-boot-samples/spring-boot-sample-devtools/src/main/java/sample/devtools/MyController.java +++ b/spring-boot-samples/spring-boot-sample-devtools/src/main/java/sample/devtools/MyController.java @@ -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); - } } diff --git a/spring-boot-samples/spring-boot-sample-devtools/src/main/resources/templates/hello.html b/spring-boot-samples/spring-boot-sample-devtools/src/main/resources/templates/hello.html index ddfe95fa00..3d310807b8 100644 --- a/spring-boot-samples/spring-boot-sample-devtools/src/main/resources/templates/hello.html +++ b/spring-boot-samples/spring-boot-sample-devtools/src/main/resources/templates/hello.html @@ -7,7 +7,9 @@

Header

-
Lorem ipsum dolor sit amet, +
+

Session Var

+ 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