Spring Boot
Spring boot port
상국이
2022. 1. 31. 15:26
728x90
* port 번호 바꾸고 싶은 경우
> application.properties 에 추가
server.port = 포트번호
* 랜덤 포트 번호 사용하고 싶은 경우
> application.properties 에 추가
server.port = 0
/*
* ${random.int} 등을 쓰면 안됨 > 이 경우 사용하지 못하는 port를 부여할 수 있음
* > 0의 경우 가용범위 내의 랜덤포트를 부여
*/
* 랜덤포트 사용하는 방법 1
@Component
public class RunListener implements ApplicationListener<ServletWebServerInitializedEvent> {
@Override
public void onApplicationEvent(ServletWebServerInitializedEvent event) {
ServletWebServerApplicationContext context = event.getApplicationContext();
System.out.println(context.getWebServer().getPort());
}
}
를 통해 포트번호를 로그로 찍음
728x90