If you are using Spring MVC + Spring Security, it might be worth checking out org.springframework.security.web.session.HttpSessionEventPublisher
The javadoc for the class says:
Publishes HttpSessionApplicationEvents to the Spring Root
WebApplicationContext.
Maps javax.servlet.http.HttpSessionListener.sessionCreated() to
HttpSessionCreatedEvent.
My understanding is that you need to add:
<listener>
<listener-class>
org.springframework.security.web.session.HttpSessionEventPublisher
</listener-class>
</listener>
And your class needs to extend ApplicationListener in order to receive these events
public class SessionPopulatorThing implements ApplicationListener<HttpSessionCreatedEvent>{
//repository, service attributes go here
public void onApplicationEvent(HttpSessionCreatedEvent httpSessionCreatedEvent){
//populate with defaults
}
}
The main benefit is that it's compatible with Spring Core + Spring Security and with a little bit of extra configuration on top of this you can get concurrency management features in session management with Spring Security as well. There's more about this in the spring security reference documentation: