Spring Sessions allows you to persist user sessions into a database. Combined with Spring Security, it is easy to create a setup where each logged in user is represented by a row in a SPRING_SESSION table. Externalising sessions into a database is also a prerequisite for a zero-downtime deployment strategy where users can stay logged in while a new application version is deployed. On paper, the integration of those two Spring components is very easy. Assuming you have a working ...

Different deployment environments (e.g., development, testing, staging and production) often require that different pieces of code are switched on and off. For example, you only want to send real emails in production and write to an email log in all other environments instead. Or your code to initialise the database should only run in the staging environment. A simple but hard to maintain way for such conditional code executions is to define a globally available variable such as isProductionSystem and write ...

Question: In my Thymeleaf template, I want to output the size of a list of objects. For example, for the list List<String> list = Arrays.asList("Go", "Python", "Scala"); the result should be 3. How is this possible using just Thymeleaf syntax? You can use the following expression: <span th:text="${#lists.size(myList)}">[Number of Elements]</span> And just in case you want to check if the list is empty, there is also an easy method for that: <span th:if="${#lists.isEmpty(myList)}">This list is empty</span> ...

Bernhard Knasmüller on Software Development