6

I'm exploring the possibilities of Spring Boot right now, and I'm at a slight impasse. I want to be able to run two Spring Boot applications at once, both on the same server, but at different paths (one deploys on /, the other deploys at /another-path).

Because this is an embedded Tomcat instance running within Spring Boot, there's no configuration files available for me to change.

Is there a standard way to do this? Is it possible?

Makoto
  • 104,088
  • 27
  • 192
  • 230
  • Spring Boot applications run in their own JVM. To get the behavior you ask for, you need both applications to be in the same JVM which is not what Spring Boot is designed for. – Thorbjørn Ravn Andersen Jan 09 '15 at 22:48

2 Answers2

21

Spring Boot comes with some pre-built property support. If you create an application.properties file, you can include:

server.port=<another port>
server.address=<another IP address>
server.sessionTimeout=<another timeout setting>
server.contextPath=/your-other-path

This can be in application.properties adjacent to your runnable JAR, embedded inside the JAR file, or simply applied as a -Dserver.contextPath=/your-alt-path with the java command. These are cascading, meaning you can embed one set of defaults inside the JAR, override with a local application.properties file, and then finally override application.properties with the -D options.

gregturn
  • 2,625
  • 3
  • 25
  • 40
  • Ah, now it's coming back to me. I remember this being discussed and demonstrated at the presentations. Thanks! – Makoto Sep 23 '13 at 15:01
  • One fine point @Makoto, Spring Boot doesn't support multiple apps running inside the same embedded container, which I'm not sure if that's precisely what you're asking. Each app runs in its own embedded container. – gregturn Sep 23 '13 at 15:31
1

As it uses an embedded tomcat you should be able to add a /META-INF/context.xml to each application which specifies the path (at least this should work for a normal tomcat).

That works for our normal embedded tomcat stuff, so I would expect it to work for Spring Boot as well.

M. Deinum
  • 115,695
  • 22
  • 220
  • 224