解决spring boot项目中连接多出jsessionid的问题

在HTML中用<input id="urlcontext" type="hidden" th:value="@{/}" /> 时会发现获得的连接会是  " /项目名/;jsessionid=xxxxxxxxxxxxxxxxxxxx"  这样的形式,这样再去拼接连接访问就会报错。web

 

  在启动类上继承   SpringBootServletInitializer  类,而后重写  onStartup  方法:spring

public void onStartup(ServletContext servletContext) throws ServletException{ super.onStartup(servletContext); servletContext.setSessionTrackingModes(Collections.singleton(SessionTrackingMode.COOKIE)); SessionCookieConfig sessionCookieConfig = servletContext.getSessionCookieConfig(); sessionCookieConfig.setHttpOnly(true); }

  这样就能够解决URL中出现的jsessionid的问题。cookie

  

  而后有个问题是session

  我在spring boot 2.0.0 RELEASE版本中使用内嵌Tomcat启动时,在application.yml中增长以下:app

server: 
  session: 
    tracking-modes: cookie

 发现不生效,org.springframework.boot.autoconfigure.web.ServerProperties 这个类也没有trackingModes这个属性。若是有人知道缘由,望能在评论中告知,不胜感激。url

相关文章
相关标签/搜索