자라선

7. 내장 톰캣 설정 수정 본문

Develop/Spring Boot

7. 내장 톰캣 설정 수정

자라선 2020. 7. 27. 15:57

WAS Servlet Container 를 포함한다.

WASJava EE(EJB, JMS, CDI, JTA, Servlet API)의 전체를 지원하지만

Servlet ContainerServlet APIJSP, JSTL를 지원한다.

톰캣또한 JSP등을 지원하기 때문에 같다고 볼수도 있지만 엄연히 다른거라 구분할 수 있어야한다.

 

https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto-embedded-web-servers

 

spring-boot-starter-web 의존성은 기본적으로 spring-boot-starter-tomcat을 포함하고 있다.

만약 다른 서블릿 컨테이너를 사용하기 위해서는 톰캣을 제외시켜야한다.

 

        <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>

 

웹 서버로 사용하지 않을려면 application.properties 에 다음과 같이 설정한다.

spring.main.web-application-type=none

 

WAS의 포트 변경시 application.properties 에서 수정한다.

server.port=8080

 

포트 0으로 입력시 비어있는 포트로 랜덤하게 서버를 올려준다.(콘솔에 포트 출력함)

servet.port=0

 

명시적으로 포트를 출력하고 싶다면. 웹서버가 실행되고 난뒤 콜백 함수로 알수 있다.

 

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

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

9. JAR 실행 및 패키징 원리  (0) 2020.07.27
8. SSL or HTTP2 설정  (0) 2020.07.27
6. 내장 톰캣  (0) 2020.07.27
5. 자동 설정 생성  (0) 2020.07.27
4. 자동 설정  (0) 2020.07.27
Comments