0

We have several classes, which are annotated with @SpringBootApplication, and we would like to run them simultaneously on the same maschine. How can we configure Spring such that there is as minimal interaction between them as possible?

We think out problems come down specifically to how Spring sets up tomcat, as we spent time exclude other implementation details as cause. Specifically, both applications accessing the same port seems to cause problems.

@SpringBootApplication
@ComponentScan
public class ServerA {
    public static void main(String[] args) { 
        final ConfigurableApplicationContext context = SpringApplication.run(ServerA.class,args);
        ...
}
BeanSalad
  • 11
  • 3
  • the only problem is the port. Here's how to set it: https://stackoverflow.com/questions/21083170/how-to-configure-port-for-a-spring-boot-application – ACV Apr 25 '19 at 15:50
  • Possible duplicate of [How to configure port for a Spring Boot application](https://stackoverflow.com/questions/21083170/how-to-configure-port-for-a-spring-boot-application) – sh.seo Apr 25 '19 at 16:38

2 Answers2

0

You can run several Spring Boot applications by adding the port number on applications.properties file. Add the port number to every property file. Don't duplicate port number.

server.port = 8081
Sahan.java
  • 70
  • 12
0

Build one jar file only and run same jar with different port by passing a port runtime.

For example:

java -jar app.jar --server.port=9000
java -jar app.jar --server.port=9001
java -jar app.jar --server.port=9002

--server.port is the suggested way by spring docs, you can pass argument using -Dserver.port=9000 also.

Yogesh Prajapati
  • 4,770
  • 2
  • 36
  • 77