springboot?實現(xiàn)不同context-path下的會話共享
實現(xiàn)不同context-path下的會話共享
目標描述
使用nginx,相同域(地址:端口)下的不同項目(context-path)實現(xiàn)redis-session會話共享
? ? @Bean
? ? public CookieSerializer cookieSerializer() {
? ? ? ? DefaultCookieSerializer serializer = new DefaultCookieSerializer();
? ? ? ? serializer.setCookieName("SESSION");
? ? ? ? serializer.setCookiePath("/");
? ? ? ? serializer.setDomainNamePattern("^.+?\\.(\\w+\\.[a-z]+)$");
? ? ? ? return serializer;
? ? }關于context-path的問題
本文來說下springboot中關于context-path的幾點說明
端口設置
Spring boot 默認端口是8080,如果想要進行更改的話,只需要修改applicatoin.properties文件,在配置文件中加入:
server.port= 9090
常用配置
######################################################## ###EMBEDDED SERVER CONFIGURATION (ServerProperties) ######################################################## #server.port=8080 #server.address= # bind to a specific NIC #server.session-timeout= # session timeout in seconds #the context path, defaults to '/' #server.context-path=/spring-boot #server.servlet-path= # the servlet path, defaults to '/' #server.tomcat.access-log-pattern= # log pattern of the access log #server.tomcat.access-log-enabled=false # is access logging enabled #server.tomcat.protocol-header=x-forwarded-proto # ssl forward headers #server.tomcat.remote-ip-header=x-forwarded-for #server.tomcat.basedir=/tmp # base dir (usually not needed, defaults to tmp) #server.tomcat.background-processor-delay=30; # in seconds #server.tomcat.max-threads = 0 # number of threads in protocol handler #server.tomcat.uri-encoding = UTF-8 # character encoding to use for URL decoding
ContextPath配置
Spring boot默認是/ ,這樣直接通過http://ip:port/就可以訪問到index頁面,如果要修改為http://ip:port/path/ 訪問的話,那么需要在Application.properties文件中加入server.context-path = /你的path,比如:spring-boot,那么訪問地址就是http://ip:port/spring-boot 路徑。
spring boot 2.0.0的ContextPath配置有變化: server.servlet.context-path=/spring-boot
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
基于OpenID?Connect及Token?Relay實現(xiàn)Spring?Cloud?Gateway
這篇文章主要介紹了基于OpenID?Connect及Token?Relay實現(xiàn)Spring?Cloud?Gateway,Spring?Cloud?Gateway旨在提供一種簡單而有效的方式來路由到API,并為API提供跨領域的關注點,如:安全性、監(jiān)控/指標和彈性2022-06-06
通過springboot+mybatis+druid配置動態(tài)數(shù)據(jù)源
這篇文章主要介紹了通過springboot+mybatis+druid配置動態(tài)數(shù)據(jù)源,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,,需要的朋友可以參考下2019-06-06

