본문 바로가기

개발중/Spring

스프링 부트 port 가져오기

728x90
반응형

@Autowired
Environment environment;
String port = environment.getProperty("local.server.port");

 

@Value("${local.server.port}")
int port;

 

@Inject
private org.springframework.boot.autoconfigure.web.ServerProperties serverProperties;

config.setHost("localhost:" + serverProperties.getPort());

 

728x90
반응형