Java 如何使用maven更改tomcat服务器的端口号

Java 如何使用maven更改tomcat服务器的端口号,java,maven,tomcat,spring-boot,Java,Maven,Tomcat,Spring Boot,我正在使用SpringMVC框架和maven编写一个Rest服务。我现在正在使用tomcat服务器。我对该项目的pom是 <?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://mav

我正在使用SpringMVC框架和maven编写一个Rest服务。我现在正在使用tomcat服务器。我对该项目的pom是

<?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>

4.0.0
org.springframework
gs休息服务
0.1.0
org.springframework.boot
spring启动程序父级
1.2.5.1发布
org.springframework.boot
SpringBootStarterWeb
1.8
org.springframework.boot
springbootmaven插件
春假
https://repo.spring.io/libs-release
春假
https://repo.spring.io/libs-release
此项目使用tomcat服务器,默认情况下在端口8080上运行。有人能帮我理解它从哪里获取这个配置,以及如何更改tomcat运行的端口吗

我的初步分析告诉我,spring.boot插件中完成了一些配置,我需要在pom中重写这些配置。有人能帮我覆盖tomcat默认端口并在其他端口上运行它吗

可以使用Spring环境属性配置公共servlet容器设置。通常,您会在
应用程序.properties
文件中定义属性

常用服务器设置包括:

  • 网络设置:侦听传入HTTP请求的端口(
    server.port
    ),绑定到
    server.address
    的接口地址等
因此,创建一个
src/main/resources/application.properties
并添加

 server.port=${port:8081}

(或您想要的任何端口)。

我们可以像这样更改spring boot应用程序的application.properties

server.port=${port:8080}

  • 转到(您的Tomcat目的地)
  • C:\Program Files\Apache软件基金会\Tomcat 8.0\conf
  • 在conf中可以找到server.xml
  • 您可以将连接器端口更改为类似以下内容

Connector port=“8081”(您想要的端口号)

我在application.properties中尝试了adding server.port语句,但可能重复。它不起作用。应用程序仍在使用spring boot指定的默认端口地址。它使用application.properties文件中的语句server.port=${port:8081}