一、代码方式(修改配置类)
@Bean public WebServerFactoryCustomizer<ConfigurableWebServerFactory> MyCustomizer(){ return new WebServerFactoryCustomizer<ConfigurableWebServerFactory>() { @Override public void customize(ConfigurableWebServerFactory factory) { Random random = new Random(); factory.setPort(random.nextInt(55536)+10000); } }; }
二、不启动端口(仅支持定时、kafka等任务,不支持get/post)
spring: main: web-application-type: none
三、若使用eureka注册中心,建议设置eureka客户端唯一id
eureka: instance: instance-id: ${spring.cloud.client.ip-address}:${random.uuid}
搜索
复制
标签:副本,Springboot,spring,random,端口,eureka,WebServerFactoryCustomizer,id From: https://www.cnblogs.com/baipengchao/p/18185140