springboot?實現不同context-path下的會話共享
實現不同context-path下的會話共享
目標描述
使用nginx,相同域(地址:端口)下的不同項目(context-path)實現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
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
使用FeignClient進行微服務交互方式(微服務接口互相調用)
這篇文章主要介紹了使用FeignClient進行微服務交互方式(微服務接口互相調用),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-03-03
SpringBoot MongoDB 索引沖突分析及解決方法
這篇文章主要介紹了SpringBoot MongoDB 索引沖突分析及解決方法,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-11-11
SpringBoot實現WebSocket即時通訊的示例代碼
本文主要介紹了SpringBoot實現WebSocket即時通訊的示例代碼,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-04-04

