I have this controller
@Controller
@RequestMapping(value = \"/login\")
public class Login{
@RequestMapping
public ModelAndView mainPage(HttpServletReque
Are you using spring security? May be you can set
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER)
if you are managing sessions by yourself
Reference: https://www.baeldung.com/spring-security-session
The real problem was at JSessionID path.
The path of JSessionID was /myapp
. That was result of Tomcat, because my app normaly run under mydom.com:8080/myapp
But with Apache as reverse proxy, I run my app directly from mydom.com/
, which make JSessionID
invalid because I'm not on mydom.com/myapp
.
So I added a new line in virtual host from Apache(where is setted reverse proxy) to change the path of cookies:
ProxyPassReverseCookiePath /myapp /
This is my final VirtualHost
and now Session persist between requests.
<VirtualHost *:80>
ServerName mydom.com
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:8080/myapp/
ProxyPassReverse / http://127.0.0.1:8080/myapp/
ProxyPassReverseCookiePath /myapp /
</VirtualHost>