下面三种都可以修改默认端口号。按需任意选择一种即可
一、添加-Dserver.port=端口号
下面示例,将默认端口号修改为6666 -Dserver.port=6666
运行结果:
二、在.properties文件添加server.port=端口号
下面示例,将默认端口号修改为7666。
在resources文件下创建一个db.properties
在db.properties
中添加 server.port=7666
运行结果:
三、在.yml文件添加
下面示例,将默认端口号修改为8888。
在application.yml
内加入:
server:
port: 8888
建议直接复制上述,将想要改的端口号改了就行,注意: port:和数字之间有一个空格!
运行效果: