How to change port number for tomcat server using maven
Solution 1
27.3.4 Customizing embedded servlet containers says (in part)
Common servlet container settings can be configured using Spring Environment properties. Usually you would define the properties in your
application.properties
file.Common server settings include:
- Network settings: listen port for incoming HTTP requests (
server.port
), interface address to bind toserver.address
, etc.
So, create a src/main/resources/application.properties
and add
server.port=${port:8081}
(or whatever port you want).
Solution 2
we can change in application.properties of spring boot application like this
server.port=${port:8080}
Mercurial
Updated on June 26, 2022Comments
-
Mercurial almost 2 years
I am writing a Rest service using spring mvc framework and maven. I am using tomcat server for now. My pom for the project is
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.springframework</groupId> <artifactId>gs-rest-service</artifactId> <version>0.1.0</version> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.2.5.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> <properties> <java.version>1.8</java.version> </properties> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> <repositories> <repository> <id>spring-releases</id> <url>https://repo.spring.io/libs-release</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>spring-releases</id> <url>https://repo.spring.io/libs-release</url> </pluginRepository> </pluginRepositories> </project>
This project uses tomcat server and runs on port 8080 by default. can anyone help me understand from where it picks up this configuration and how to change the port on which tomcat runs.
My preliminary analysis tells me there is some configuration done in spring.boot plugin that I need to override in my pom. Can anyone help me in overriding tomcat default port and run it on some other port.
-
Mercurial about 8 yearsI tried the adding server.port statement in application.properties. It didn't work. The application is still picking up default port address specified by spring boot.
-
Mercurial about 8 yearsIt worked with statement server.port=${port:8081} in application.properties file