4

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,205
  • 1
  • 16
  • 32
napstablook
  • 339
  • 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

2 Answers2

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,205
  • 1
  • 16
  • 32
João Paraná
  • 974
  • 9
  • 17
0

If you want to change spring boot default port without change any code you should pass port number in spring boot run command as

  java -jar -Dserver.port=8090 hello-spring-boot.jar

Now your application will use 8090 port.

Reference : How to Change the default port in Spring Boot

In Other method we can add server.port property in application.properties file

    server.port = 8090
php king
  • 105
  • 2
  • 2
  • 12