Reputation: 1695
I am new with Maven/SpringBoot and trying to deploy a repository with different Tomcat Server port.
By default, I would be happy to run tomcat on :8080. But today, I wanted to add Jenkins pipelines to my project and I deployed tomcat on :8080 (with jenkins on it) before my spring cloud gateway repository.
Now, once I try to deploy gateway, compiler obviously says address :8080 already in use
.
Now, I want my gateway to deploy Tomcat on another port, (or use already-existing tomcat on :8080 if possible?) so I wanted to deploy it using this command:
$ mvn spring-boot:run -Dserver.port=8181
However, same error based on :8080
happens to appear:
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.5.8.RELEASE:run (default-cli) on project crw-gateway: An exception occurred while running. null: InvocationTargetException: Connector configured to listen on port 8080 failed to start.
I tried putting server.port=8080
to application.properties
or application-dev.properties
files but I cant override it.
Any ideas? How can I override the port? Is there a possibility that I can use already existing tomcat-server on :8080?
Thank you for your time!
EDIT: I had my configurations under ~/config folder. There, I had gateway.properties
, which included the line server.port=8080
. It has overridden the command line interface as the accepted answer asserts. Changing it to 8888 worked.
Upvotes: 3
Views: 1607
Reputation: 4558
According to Spring Boot documentation :
Spring Boot uses a very particular PropertySource order that is designed to allow sensible overriding of values. Properties are considered in the following order:
- Devtools global settings properties on your home directory (
~/.spring-boot-devtools.properties
when devtools is active).@TestPropertySource
annotations on your tests.- @
SpringBootTest#properties
annotation attribute on your tests.- Command line arguments.
- Properties from
SPRING_APPLICATION_JSON
(inline JSON embedded in an environment variable or system property).ServletConfig
init parameters.ServletContext
init parameters.- JNDI attributes from
java:comp/env
.- Java System properties (
System.getProperties()
).- OS environment variables.
- A
RandomValuePropertySource
that has properties only inrandom.*
.- Profile-specific application properties outside of your packaged jar (
application-{profile}.properties
and YAML variants).- Profile-specific application properties packaged inside your jar (
application-{profile}.properties
and YAML variants).- Application properties outside of your packaged jar (
application.properties
and YAML variants).- Application properties packaged inside your jar (
application.properties
and YAML variants).@PropertySource
annotations on your@Configuration
classes.- Default properties (specified by setting
SpringApplication.setDefaultProperties
).
So your problem is that your command line (4.) can not override the application.properties
file configuration (13., 14., 15.).
If you want to override the server.port
property, you need to ensure to respect this order in your configuration.
Upvotes: 2