스프링 부트 개념과 활용
3. 스프링 부트 원리
포스팅 참조 정보
GitHub
공부한 내용은 GitHub에 공부용 Organizations에 정리 하고 있습니다
해당 포스팅에 대한 내용의 GitHub 주소
실습 내용이나 자세한 소스코드는 GitHub에 있습니다
포스팅 내용은 간략하게 추린 핵심 내용만 포스팅되어 있습니다
https://github.com/freespringlecture/springboot-concept-uses/tree/chap03-06-containerandport
freespringlecture/springboot-concept-uses
백기선님의 스프링 부트 개념과 활용 강의 내용 정리. Contribute to freespringlecture/springboot-concept-uses development by creating an account on GitHub.
github.com
해당 포스팅 참고 인프런 강의
https://www.inflearn.com/course/%EC%8A%A4%ED%94%84%EB%A7%81%EB%B6%80%ED%8A%B8/dashboard
스프링 부트 개념과 활용 - 인프런
스프링 부트의 원리 및 여러 기능을 코딩을 통해 쉽게 이해하고 보다 적극적으로 사용할 수 있는 방법을 학습합니다. 중급 프레임워크 및 라이브러리 Spring Spring Boot 온라인 강의
www.inflearn.com
실습 환경
- Java Version: Java 11
- SpringBoot Version: 2.1.2.RELEASE
6. 내장 웹 서버 응용 1부: 컨테이너와 포트
컨테이너와 포트
다른 서블릿 컨테이너로 변경
https://docs.spring.io/spring-boot/docs/current/reference/html/howto-embedded-web-servers.html
78. Embedded Web Servers
Each Spring Boot web application includes an embedded web server. This feature leads to a number of how-to questions, including how to change the embedded server and how to configure the embedded server. This section answers those questions. 78.2 Disabling
docs.spring.io
tomcat, jetty, undertow
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<!-- Exclude the Tomcat dependency -->
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Use Jetty instead -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
웹서버 사용하지 않기
Spring Boot Reference Guide
docs.spring.io
WebServlet 의존성들이 클래스패스에 있더라도 무시하고 그냥 None WebApplication으로 실행하고 끝냄
application.properties
에 아래 설정
spring.main.web-application-type=none
@SpringBootApplication
에 설정
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication application = new SpringApplication(Application.class);
application.setWebApplicationType(WebApplicationType.NONE);
application.run(args);
}
}
포트
server.port
랜덤포트
아래와 같이 설정하면 랜덤으로 사용할 수 있는 포트 찾아서 띄워줌
server.port=0
ApplicationListner<ServletWebServerInitializedEvent>
위와 같이 지정한 포트를 Application에서 어떻게 사용할 것인가
이벤트 리스너 생성
웹서버가 생성이 되면 servletWebServer가 실행되고 이 이벤트 리스너 핸들러가 호출이 되고 onApplicationEvent 콜백이 실행됨
웹 애플리케이션 컨텍스트 이므로 웹서버를 알 수 있고 웹서버에서 포트 정보를 가져올 수 있음
@Component
public class PortListener implements ApplicationListener<ServletWebServerInitializedEvent> {
@Override
public void onApplicationEvent(ServletWebServerInitializedEvent event) {
ServletWebServerApplicationContext applicationContext = event.getApplicationContext();
applicationContext.getWebServer().getPort();
}
}
Enable HTTP Response Compression
응답을 압축 해서 보냄
server.compression.enabled=true
'개발강의정리 > Spring' 카테고리의 다른 글
[스프링 부트 개념과 활용] 3-8. 독립적으로 실행 가능한 JAR (0) | 2019.10.20 |
---|---|
[스프링 부트 개념과 활용] 3-7. 내장 웹 서버 응용 2부: HTTPS와 HTTP2 (0) | 2019.10.19 |
[스프링 부트 개념과 활용] 3-5. 내장 웹 서버 이해 (0) | 2019.10.17 |
[스프링 부트 개념과 활용] 3-4. 자동 설정 만들기 (0) | 2019.10.16 |
[스프링 부트 개념과 활용] 3-3. 자동 설정 이해 (0) | 2019.10.15 |
댓글