5

I have two applications that I need to run simultaneously, and both are trying to run on port 8080. I'd like to change one of them to port 9000. The application I'm trying to change has spring security, so it runs on port 8443 when using https and port 8080 when using http. I have to move it from port 8080 without changing any .java files. Also, I need to run the other application on port 8080 as well, so changing the default tomcat port wouldn't be a good idea.

I tried adding to application.properties the lines server.port=9000, spring.main.server.port=9000, then running mvn install, and then java -jar target/app.jar.

I also tried running java -jar target/app.jar with different flags: -Dserver.port=9000 and --server.port=9000.

Regardless, I get - Tomcat started on port(s): 8443 (https) 8080 (http).

So, my questions are:

  • How do I get it to run on a port different from 8080?
  • And, what could be causing the configuration files to not change the port?
UrsinusTheStrong
  • 1,239
  • 1
  • 16
  • 33
napstablook
  • 349
  • 3
  • 7
  • 15
  • Spring Boot will only start on a single port by default so your application must contain some code that's configuring Tomcat's connectors. I suspect that code is preventing server.port from having any effect, possibly because the port numbers have been hard-coded. Can you share the code that's configuring Tomcat's connectors? – Andy Wilkinson May 13 '16 at 17:04

1 Answers1

6

Run the following command:

mvn spring-boot:run -Drun.jvmArguments='-Dserver.port=8088'

Add the following plugin to your pom.xml file

<build>
    . . . 
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
UrsinusTheStrong
  • 1,239
  • 1
  • 16
  • 33
João Paraná
  • 1,031
  • 1
  • 9
  • 18