您的位置:首页 > 编程语言 > Java开发

spring-boot怎么更改默认的端口号

2017-11-20 15:07 471 查看
方法一:可以通过实现EmbeddedServletContainerCustomizer接口来实现,代码:
package com.springboot1;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;

@SpringBootApplication
public class Springboot1Application implements EmbeddedServletContainerCustomizer {

public static void main(String[] args) {
SpringApplication.run(Springboot1Application.class, args);
}

@Override
public void customize(ConfigurableEmbeddedServletContainer configurableEmbeddedServletContainer) {
configurableEmbeddedServletContainer.setPort(8011);
}
}
方法二:更加简单
在src/resource下增加文件application.properties
加入server.port=8081
即可
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: