admin管理员组文章数量:1130349
写在前面
SpringBoot很适合WEB应用的开发,该框架可以使用嵌入的TOMCAT/JETTY/UNDERTOW或者NETTY来创建self-contained HTTP server。大部分WEB应用使用spring-boot-starter-web来快速开发,也可以使用spring-boot-starter-webflux 来开发基于反应式的WEB应用。如果使用SpringBoot框架,但不是WEB应用呢?
场景描述
创建了一个基于SpringBoot框架的工程,但是在当前模块中并不需要对外提供REST服务,也不需要端口,针对这个场景,则在POM.XML中去掉了如下配置(如果这样的话,系统中没有常驻线程/监听的话,启动之后就会自动关闭),但是在该场景下启动依然会报错:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
错误描述
启动工程时报错(注意上面的场景描述):
Identify and stop the process that’s listening on port 8080 or configure this application to listen on another port.
问题分析
由于引入了其他的模块,其他模块中将spring-boot-starter-web引入了,而当前模块中又未配置端口,所以启动时SPRINGBOOT会默认使用端口8080,而部署环境中其他项目已将8080占用,所以启动时系统报端口被占用。
当然模块本身需要端口,而端口又被占用时的处理方式与该场景不一样。
如何解决
SPRING BOOT采用不占端口的方式启动。
①. 方式一,通过API指定:
public class MyApplication {
public static void main(String[] args) {
new SpringApplicationBuilder(MyApplication.class).web(WebApplicationType.NONE).run(args);
// SpringApplication.run(MyApplication.class, args);
log.info("后端服务启动成功, 正在监听中...");
}
}
②. 方式二,通过参数配置:
写在前面
SpringBoot很适合WEB应用的开发,该框架可以使用嵌入的TOMCAT/JETTY/UNDERTOW或者NETTY来创建self-contained HTTP server。大部分WEB应用使用spring-boot-starter-web来快速开发,也可以使用spring-boot-starter-webflux 来开发基于反应式的WEB应用。如果使用SpringBoot框架,但不是WEB应用呢?
场景描述
创建了一个基于SpringBoot框架的工程,但是在当前模块中并不需要对外提供REST服务,也不需要端口,针对这个场景,则在POM.XML中去掉了如下配置(如果这样的话,系统中没有常驻线程/监听的话,启动之后就会自动关闭),但是在该场景下启动依然会报错:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
错误描述
启动工程时报错(注意上面的场景描述):
Identify and stop the process that’s listening on port 8080 or configure this application to listen on another port.
问题分析
由于引入了其他的模块,其他模块中将spring-boot-starter-web引入了,而当前模块中又未配置端口,所以启动时SPRINGBOOT会默认使用端口8080,而部署环境中其他项目已将8080占用,所以启动时系统报端口被占用。
当然模块本身需要端口,而端口又被占用时的处理方式与该场景不一样。
如何解决
SPRING BOOT采用不占端口的方式启动。
①. 方式一,通过API指定:
public class MyApplication {
public static void main(String[] args) {
new SpringApplicationBuilder(MyApplication.class).web(WebApplicationType.NONE).run(args);
// SpringApplication.run(MyApplication.class, args);
log.info("后端服务启动成功, 正在监听中...");
}
}
②. 方式二,通过参数配置:
本文标签: 解决方案StopIdentifySpringBootprocess
版权声明:本文标题:SpringBoot - Identify and stop the process that‘s listening on port 8080解决方案 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/jiaocheng/1763732747a2958611.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论