Spring Boot修改启动端口的方法
作者:jingxian 时间:2022-02-10 05:49:55
spring boot是个好东西,可以不用容器直接在main方法中启动,而且无需配置文件,方便快速搭建环境。可是当我们要同时启动2个springboot工程时,就会有问题,有可能会因为8080端口被第一个应用占用而导致第二个应用无法启动,这时就需要修改其中一个工程的启动端口。
1、可以通过实现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);
}
}
2、可以通过application.properties配置文件来实现
server.port=8084
标签:spring,boot,启动端口
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
SpringBoot redis分布式缓存实现过程解析
2023-10-10 22:32:25
![](https://img.aspxhome.com/file/2023/1/58541_0s.png)
Java 信号量Semaphore的实现
2023-06-19 11:00:34
Java的“Goto”与标签及使用详解
2023-11-11 03:56:09
Java 开启多线程常见的4种方法
2023-11-23 02:30:10
![](https://img.aspxhome.com/file/2023/0/58580_0s.png)
Java import导入及访问控制权限修饰符原理解析
2023-08-17 21:42:59
解决mybatis update并非所有字段需要更新问题
2022-12-09 10:20:55
![](https://img.aspxhome.com/file/2023/9/61599_0s.jpg)
Java语言读取配置文件config.properties的方法讲解
2023-09-29 14:45:51
![](https://img.aspxhome.com/file/2023/9/86759_0s.png)
Android开发之自定义加载动画详解
2023-07-27 01:41:05
![](https://img.aspxhome.com/file/2023/0/85980_0s.png)
Java编程接口回调一般用法代码解析
2023-11-11 06:55:11
Java IO流 文件传输基础
2023-08-24 13:27:11
![](https://img.aspxhome.com/file/2023/0/58070_0s.png)
Flutter加载图片流程之ImageCache源码示例解析
2023-07-04 01:56:23
c#中CAD文件读取实例
2023-07-23 19:37:59
浅谈Java中Map和Set之间的关系(及Map.Entry)
2023-08-25 02:23:48
![](https://img.aspxhome.com/file/2023/9/57949_0s.jpg)
springboot集成mybatisPlus+多数据源的实现示例
2023-11-24 22:35:02
![](https://img.aspxhome.com/file/2023/4/59924_0s.png)
Java利用MultipartFile实现上传多份文件的代码
2023-11-25 11:29:13
SpringBoot整合mybatis的方法详解
2023-09-02 06:23:57
![](https://img.aspxhome.com/file/2023/5/58455_0s.png)
Zookeeper和Eureka哪个更好?
2023-11-10 02:57:35
可视化Swing中JTable控件绑定SQL数据源的两种方法深入解析
2023-11-28 19:13:58
![](https://img.aspxhome.com/file/2023/3/60283_0s.jpg)
如何让java只根据数据库表名自动生成实体类
2022-02-24 04:25:52
![](https://img.aspxhome.com/file/2023/2/61322_0s.png)
java中Vector类的常用方法详解
2023-11-26 10:29:07
![](https://img.aspxhome.com/file/2023/4/60234_0s.png)