다른 서블릿 컨테이너로 변경

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jetty</artifactId>
</dependency>

웹 서버 사용하지 않기

application.properties

spring.main.web-application-type=none

포트

application.properties

server.port=7070

랜덤 포트

server.port=0

ApplicationListner<ServletWebServerInitializedEvent>

띄어진 포트 확인 방법

@Component
public class PortListener implements ApplicationListener<ServletWebServerInitializedEvent> {
	@Override
	public void onApplicationEvent(ServletWebServerInitializedEvent servletWebServerInitializedEvent) {
		ServletWebServerApplicationContext applicationContext = servletWebServerInitializedEvent.getApplicationContext();
		System.out.println(applicationContext.getWebServer().getPort());
	}
}