Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change port number for tomcat server using maven

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.

like image 675
Mercurial Avatar asked Oct 26 '25 10:10

Mercurial


1 Answers

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 to server.address, etc.

So, create a src/main/resources/application.properties and add

 server.port=${port:8081}

(or whatever port you want).

like image 127
Elliott Frisch Avatar answered Oct 28 '25 01:10

Elliott Frisch