如何设置springboot启动端口
作者:mrr 时间:2021-05-30 01:07:24
spring boot是个好东西,可以不用容器直接在main方法中启动,而且无需配置文件,方便快速搭建环境。可是当我们要同时启动2个springboot工程时,就会有问题,有可能会因为8080端口被第一个应用占用而导致第二个应用无法启动,这时就需要修改其中一个工程的启动端口。
可以通过实现EmbeddedServletContainerCustomizer接口来实现:
public class Application extends SpringBootServletInitializer implements EmbeddedServletContainerCustomizer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(Application.class);
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
container.setPort(8081);
}
}
PS:下面看下spring boot创建应用端口冲突8080
如果你电脑上的8080端口号被其它程序(如jenkins)占用了,则运行lightsword会报以下错误:java.net.BindException: Address already in use......Failed to start component [Connector[HTTP/1.1-8080]]...
解决方法:在src->main->resources目录下新建一个文件,名称为application.properties(这是SpringBoot统一的配置文件)加了以下一行内容:(取个电脑上可用的端口号,如下面的9527,看过星爷电影的都懂的)server.port = 9527
再次运行即可。
总结
以上所述是小编给大家介绍的如何设置springboot启动端口网站的支持!
标签:spring,boot,端口
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Android短信验证服务分享
2023-04-04 12:35:59
详解Unity安卓共享纹理
2022-07-10 08:18:21
![](https://img.aspxhome.com/file/2023/1/111161_0s.png)
C#实现批量更改文件名称大小写或扩展名
2023-03-25 02:20:50
![](https://img.aspxhome.com/file/2023/9/88429_0s.png)
java方法及this关键字原理分析详解
2021-08-16 07:51:35
![](https://img.aspxhome.com/file/2023/4/73054_0s.png)
C#文件上传的简单实现
2021-06-02 19:06:04
![](https://img.aspxhome.com/file/2023/1/102291_0s.jpg)
Echarts+SpringMvc显示后台实时数据
2021-06-08 03:38:42
![](https://img.aspxhome.com/file/2023/4/110794_0s.jpg)
Java Swing JComboBox下拉列表框的示例代码
2022-09-16 00:24:50
![](https://img.aspxhome.com/file/2023/6/79886_0s.gif)
C#创建、读取和修改Excel的方法
2023-02-24 06:28:16
Java使用arthas修改日志级别详解
2023-02-04 23:09:26
![](https://img.aspxhome.com/file/2023/8/85398_0s.png)
SpringBoot集成阿里云OSS图片上传
2021-08-15 21:01:55
![](https://img.aspxhome.com/file/2023/9/66979_0s.jpg)
Android Google AutoService框架使用详解
2023-07-19 22:48:14
![](https://img.aspxhome.com/file/2023/3/89513_0s.png)
Android如何监听屏幕旋转
2021-12-15 06:12:50
![](https://img.aspxhome.com/file/2023/3/91693_0s.png)
Java单元测试Powermockito和Mockito使用总结
2021-11-12 14:59:07
详解使用JavaCV/OpenCV抓取并存储摄像头图像
2023-05-08 07:23:31
Android自定义带圆点的半圆形进度条
2023-08-05 07:47:15
![](https://img.aspxhome.com/file/2023/0/86750_0s.png)
springboot如何实现自动装配源码解读
2023-11-10 15:44:20
一行java代码实现高斯模糊效果
2023-02-07 17:31:34
![](https://img.aspxhome.com/file/2023/5/78975_0s.jpg)
Java实现常用缓存淘汰算法:FIFO、LRU、LFU
2022-08-26 21:45:19
java的基本数据类型及属性
2021-08-10 19:31:49
Swagger及knife4j的基本使用详解
2023-02-13 09:34:00