Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a standard way to customize the deploy path in Spring Boot?

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?

like image 662
Makoto Avatar asked Sep 13 '13 00:09

Makoto


People also ask

How do you specify file path in application properties in spring boot?

properties in default location. Spring Boot loads the application. properties file automatically from the project classpath. All you have to do is to create a new file under the src/main/resources directory.

What is default context path in spring boot?

By default, Spring Boot serves the content on the root context path (“/”). So, any Boot application with default configuration can be accessed as: http://localhost:8080/ However, in some cases, we may wish to change the context of our application. There are multiple ways to configure the context path, and application.


2 Answers

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.

like image 106
gregturn Avatar answered Sep 29 '22 09:09

gregturn


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.

like image 38
M. Deinum Avatar answered Sep 29 '22 07:09

M. Deinum