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

来源:互联网 发布:淘宝开店要注册公司吗 编辑:程序博客网 时间:2024/05/21 06:41

方法一:可以通过实现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;@SpringBootApplicationpublic 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
即可


阅读全文
0 0