Skip to content
Advertisement

Spring Boot session scoped bean

I am trying to understand how the Session scoped bean work and have tried the example from here.

HelloMessageGenerator.java

JavaScript

HelloMessageBean.java

JavaScript

HelloMessageController.java

JavaScript

When I go to http://localhost:8080/scopes/session I get an error.

scopesExample.html

JavaScript

The error I am getting is as if the mapping would not exist:

JavaScript

Advertisement

Answer

I was missing the thymeleaf dependency in the pom.

JavaScript

This is why I was getting a 404 when going to localhost:8080/scopes/request

After adding the thymeleaf dependency the bean scope was working as expected. For a session scope bean the bean is created only once per session or after the configured session timeout. For a request scope bean it is created for every request (ie. each time one hits the endpoint).

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement