Hi,
I had created below class in jmix 2.0 but getting package error for WebSessionInitializedEvent
and WebSessionDestroyedEvent
this is working in jmix 1.5 to manually invalidate HttpSession
every time VaadinSession
is expired. To do this, you need to create a Spring bean and add WebSessionDestroyedEvent
EventListener
jmix.ui.httpSessionExpirationTimeoutSec=120
vaadin.servlet.heartbeatInterval=-1
vaadin.servlet.close-idle-sessions=true
main.datasource.hikari.connection-timeout=900000
Added above configuration still session not getting destroyed
import com.vaadin.flow.server.VaadinRequest;
import com.vaadin.flow.server.WrappedHttpSession;
import com.vaadin.flow.server.WrappedSession;
import jakarta.servlet.http.HttpSession;
import org.slf4j.Logger;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
@Component
public class SessionListener {
private static final Logger log = org.slf4j.LoggerFactory.getLogger(SessionListener.class);
@EventListener
public void onWebSessionInitialized(WebSessionInitializedEvent event) {
WrappedSession wrappedSession = VaadinRequest.getCurrent().getWrappedSession();
String sessionId = wrappedSession != null ? wrappedSession.getId() : "";
log.info("WebSessionInitializedEvent. Session Id: " + sessionId);
}
@EventListener
public void onWebSessionDestroyed(WebSessionDestroyedEvent event) {
WrappedSession wrappedSession = VaadinRequest.getCurrent().getWrappedSession();
if (wrappedSession instanceof WrappedHttpSession) {
HttpSession httpSession = ((WrappedHttpSession) wrappedSession).getHttpSession();
httpSession.invalidate();
log.info("Invalidate HttpSession: " + httpSession.getId());
}
String sessionId = wrappedSession != null ? wrappedSession.getId() : "";
log.info("WebSessionInitializedEvent. Session Id: " + sessionId);
}
}