简体   繁体   English

如何在同一台服务器上运行两个 Spring Boot 应用程序?

[英]How to run two spring boot applications on same server?

I have two Spring Boot applications.我有两个 Spring Boot 应用程序。 I want them to run on different ports at the same time on the server, right now I'm testing it locally on my computer and when I run both jars and I'm using one application, the other one would refresh and logout.我希望它们同时在服务器上的不同端口上运行,现在我正在我的计算机上本地测试它,当我运行两个 jar 并且我正在使用一个应用程序时,另一个会刷新并注销。 I can't use both applications at the same time.我不能同时使用这两个应用程序。

Is this a problem with the embedded server, spring boot or something else?这是嵌入式服务器的问题,spring boot还是其他什么? I've read a couple of articles but I'm not sure why is this or how to solve this in the best way.我已经阅读了几篇文章,但我不确定这是为什么或如何以最佳方式解决这个问题。 Should I package both apps as WAR and run them using Apache Tomcat, or is there a newest way to do this with spring boot and the jar packaging?我应该将这两个应用程序打包为 WAR 并使用 Apache Tomcat 运行它们,还是有最新的方法可以使用 spring boot 和 jar 打包来执行此操作?

The sessions are based on cookie and the cookie is saved based on the name and the hostname.会话基于 cookie,cookie 是根据名称和主机名保存的。 For example if you are running two spring boot or tomcat applications and try to connect on these 2 applications:例如,如果您正在运行两个 spring boot 或 tomcat 应用程序并尝试连接这两个应用程序:

  • For the first application (running in localhost:8080), a session is created with by default a name JSESSIONID and the host localhost对于第一个应用程序(在 localhost:8080 中运行),默认情况下使用名称 JSESSIONID 和主机 localhost 创建会话
  • For the second application (running in localhost:8090), a session is created with by default a name JSESSIONID and the host localhost and will invalidate the first application.对于第二个应用程序(在 localhost:8090 中运行),默认情况下使用名称 JSESSIONID 和主机 localhost 创建一个会话,这将使第一个应用程序无效。

You can:你可以:

  • change the url (for example app1:8080 and app2:8090).更改网址(例如 app1:8080 和 app2:8090)。
  • Change the session cookie name which depends on your architecture/server.更改取决于您的架构/服务器的会话 cookie 名称。 For Spring Boot, you can change it this way: server.servlet.session.cookie.name = ANOTHERSESSIONID对于 Spring Boot,您可以这样更改:server.servlet.session.cookie.name = ANOTHERSESSIONID

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何远程调试在相同容器中运行的具有相同代码库但配置文件不同的两个spring boot应用程序? - How to remote debug two spring boot applications running in the same container with the same codebase but with different profiles? 如何在同一个 jvm 上运行两个 spring boot 应用程序? - How to run two spring boot application on a same jvm? 从两个不同的 Spring 引导应用程序访问相同的 MongoRepository 集合 - Accessing the same MongoRepository collection from two different Spring Boot Applications 如何使用相同的log4j.properties文件记录两个不同的Spring-Boot应用程序? - How to log with same log4j.properties files for two different Spring-Boot Applications? Spring启动运行多个应用程序 - Spring boot run multiple applications 如何在同一个 Tomcat 上部署多个带有外部配置的 Spring Boot 应用程序? - How to deploy multiple Spring boot applications with external configurations on the same Tomcat? 如何从 2 个不同的 spring 引导应用程序访问相同的数据库 - How to access the same DB from 2 different spring boot applications 如何运行两个不同的 spring 启动实例? - how to run two different spring boot instances? Spring Boot - 在两个应用程序之间交谈 - Spring Boot - talking between two applications 在服务器上运行Spring Boot应用程序 - Run spring boot application on server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM