MrRene
MrRene

Reputation: 194

How to run two spring boot applications on same server?

I have two Spring Boot applications. 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. I can't use both applications at the same time.

Is this a problem with the embedded server, spring boot or something else? 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?

Upvotes: 2

Views: 2975

Answers (1)

Jean-Christophe Gueriaud
Jean-Christophe Gueriaud

Reputation: 1378

The sessions are based on cookie and the cookie is saved based on the name and the hostname. For example if you are running two spring boot or tomcat applications and try to connect on these 2 applications:

  • For the first application (running in localhost:8080), a session is created with by default a name JSESSIONID and the host 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.

You can:

  • change the url (for example app1:8080 and app2:8090).
  • Change the session cookie name which depends on your architecture/server. For Spring Boot, you can change it this way: server.servlet.session.cookie.name = ANOTHERSESSIONID

Upvotes: 13

Related Questions