본문 바로가기
Spring Boot

Spring boot port

by 상국이 2022. 1. 31.
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

'Spring Boot' 카테고리의 다른 글

Spring boot package  (0) 2022.02.05
Spring boot SSL 사용  (0) 2022.02.01
spring boot 내장 웹 서버 변경  (0) 2022.01.31
Spring boot 내장 Servlet Container  (0) 2022.01.29
Starter & AutoConfigure  (0) 2022.01.29

댓글