0
点赞
收藏
分享

微信扫一扫

Spring Boot 自定义端口等


一、Spring Boot 1.X

/**
* Created by jiankunking on 2018/2/26.
*/
@RestController
@EnableAutoConfiguration
public class CustomPortController implements EmbeddedServletContainerCustomizer
/**
* 自定义端口
*
* @param
public void customize(ConfigurableEmbeddedServletContainer container) {
container.setPort(EnvionmentVariables.PORT);
}

@RequestMapping("/")
public String setPort(int port) {
return

二、Spring Boot 2.X

package com.jiankunking.elasticsearch.extension.customizer;

import com.jiankunking.elasticsearch.extension.config.EnvionmentVariables;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.web.bind.annotation.RestController;

/**
* @author jiankunking.
* @date:2018/8/17 10:05
* @description:
*/
@RestController
@EnableAutoConfiguration
public class CustomPortController implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> {
@Override
public void customize(ConfigurableServletWebServerFactory factory) {
//设置自定义监听端口,我这里是从环境变量取的
factory.setPort(EnvionmentVariables.LISTEN_PORT);

个人微信公众号:

Spring Boot 自定义端口等_spring

作者:jiankunking


举报

相关推荐

0 条评论