关于端口号占用问题
1.重复开启当前服务,这里我开启了8080端口,正常跑通了,在初始学习时,对于端口号并不了解,在做出一些代码改动后我重跑了程序,于是就出现端口号复用的报错.
信息: Initializing ProtocolHandler ["http-bio-8080"] 八月 18, 2022 3:49:40 下午 org.apache.coyote.AbstractProtocol init 严重: Failed to initialize end point associated with ProtocolHandler ["http-bio-8080"] java.net.BindException: Address already in use: JVM_Bind <null>:8080
意思为初始化8080端口失败,因为上次启动的服务还在运行,此时只要将上次服务关闭或者在原服务上重启就行。
2.被未知服务占用端口号
(1)最简单的方式是换个端口号,以spring配置pom.xml文件为例,若为spring boot 程序的话,直接在配置文件中修改Server port即可。
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<port>8080</port>
<path>/</path>
</configuration>
</plugin>
(2)若非要使用这个端口号,可在控制台命令行杀掉该进程
netstat -ano | findstr 端口号
taskkill /f /pid 占用端口号的进程