(资料图)

本文环境

1.SpringBoot 2.2.6 2.jdk 1.8.0_241

一、使用java修改端口

通过实现WebServerFactoryCustomizer接口实现,springboot2.X之前的版本会有所不同。

@SpringBootApplicationpublic class SpringbootApplication implements WebServerFactoryCustomizer{private static final Logger Log = LoggerFactory.getLogger(SpringbootApplication.class);    public static void main(String[] args) {SpringApplication.run(SpringbootApplication.class, args);    }    @Override    public void customize(ConfigurableWebServerFactory factory) {// 修改端口号        factory.setPort(12345);    }}

二、springboot打包项目

pom.xml文件添加如下内容(没有代理的话不一定可以更新成功,无法下载jar包):

org.springframework.bootspring-boot-maven-plugincom.cl.graph.SpringbootApplicationrepackageorg.apache.maven.pluginsmaven-compiler-plugin88

使用maven的package命令打包。

推荐内容