인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

Inflearn Community Q&A

fourier's profile image
fourier

asked

Spring Boot Concepts and Utilization

Embedded Web Server Application Part 1: Containers and Ports

공식문서와 예시

Written on

·

217

0

안녕하세요.

강의 속에서 다음과 같은 코드를 보여 주셨는데요. 첨부해 주신 공식문서에는 이런 예시가 없더라구요. 보통 이런 기본적인 예시 코드들은 공식 문서가 아니라면 어디에서 찾을 수 있을까요?

@Component

public class PortListener implements ApplicationListener<ServletWebServerInitializedEvent> {

@Override

public void onApplicationEvent(ServletWebServerInitializedEvent servletWebServerInitializedEvent) {

ServletWebServerApplicationContext applicationContext = servletWebServerInitializedEvent.getApplicationContext();

System.out.println(applicationContext.getWebServer().getPort());

}

}

javaspring-bootspring

Answer 1

0

whiteship님의 프로필 이미지
whiteship
Instructor

랜덤 포트로 서버를 띄우고 해당 포트 정보를 알아내는 방법이 생각보다 '기본적인 예'에 해당하지는 않습니다. 랜덤 포트로 띄우는 방법은 테스트 할 때나 일반적인 경우에 해당할 것이지, 실제 운영 서버를 그렇게 띄운다는건.. 조금 특이한 경우죠. 그런데 그런 특이한 경우도 워낙 유저들이 많다보니 비슷한 고민을 한 사람들이 많습니다. 그게 스프링 같은 대중적인 프레임워크의 장점이고요. 결론은 구글링으로 찾아냈습니다.

https://stackoverflow.com/questions/30312058/spring-boot-how-to-get-the-running-port/36391145

fourier's profile image
fourier

asked

Ask a question