本文环境

1.SpringBoot 2.2.6
2.jdk 1.8.0_241

一、使用java修改端口

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

@SpringBootApplication
public class SpringbootApplication implements WebServerFactoryCustomizer<ConfigurableWebServerFactory> {
    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打包项目

  1. pom.xml文件添加如下内容(没有代理的话不一定可以更新成功,无法下载jar包):
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <mainClass>com.cl.graph.SpringbootApplication</mainClass>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>8</source>
                <target>8</target>
            </configuration>
        </plugin>
    </plugins>
</build>
  1. 使用maven的package命令打包。

点击package打包