Spring Boot creates new JSESSIONID on each request

1.4k Views Asked by At

Spring Boot application runs on https://localhost:8080 and front-end (Angular) app runs on https://localhost:4200. On each request new JSESSIONID gets set/created as if HTTP session engine does not recognize JSESSIONID it has just set for previous request. But when I start serving front-end app as static content from Spring Boot app (which means same port for Angular app) everything works fine.

UPDATE 1: so far I have tracked that this happens because Request object get recycled because this code return false enter image description here

enter image description here

UPDATE 2: I now see that "cookie" header like this one is not present in the request when font-end runs on different port.

cookie = SLG_G_WPT_TO=en; SLG_GWPT_Show_Hide_tmp=undefined; SLG_wptGlobTipTmp=undefined; JSESSIONID=6C59D1FE6310EE1E141FD96236D9218A

When this code is run: enter image description here

1

There are 1 best solutions below

0
user435421 On

I overlooked that even though the browser showed me (in Cookies tab) that JSESSIONID cookie was present it actually was not sent with the request. I did not notice that Cookie header was not present in the requests. I am adding screenshot where a) Cookies tab is present and if opened shows JSESSIONID which gave me the idea that the cookie is being sent and b) where you can see that Cookie header is present in the correct request: enter image description here

Why Cookie header was not present? Because even though the configuration for CORS was correct on Angular side: enter image description here but HTTP interceptor's registration was commented in the AppModule: enter image description here