-
내장 웹 서버 응용 ( 톰켓 말고 다른 서버 사용하기)웹개발/SpringBoot 2020. 4. 3. 16:34
springboot stater 에 속해져 있는 tomcat를 먼저 빼줘야 한다
pom.xml 스프링부트에 있는 tomcat를 뺀다. 새로운 의존성으로 사용하고 싶은 서블릿 컨테이너의 의존성을 stater를 통해서 넣는다
새로운 웹서버 제티 삽입 톰캣이 사라지고 제티가 추가됬다 포트변경
application.properties 파일
server.port = 7070
랜덤포트변경
application.properties
server.port = 0
랜덤하게 뜨는 포트 혹은 고정시킨 포트를 애플리케이션이 어떻게 확인하고 쓸 것 인가.
The best way
ApplicationListner <ServletWebServerInitializedEvent> API에서 추천해주는 방식이다
@component public class PortListener implements ApplicationListener<ServletWebServerInitializedEvent>{ @override public void onApplicationEvent(ServletWebServerInitalizedEvent servletWebServerInitalizedEvent){ //웹에플레이션 컨텍스트를꺼낸다 ServletWebServerApplicationContext applicationContext = servletWebServerInitalizedEvent.getApplicationContext(); applicationContext.getWebServer().getPort(); //내장 웹서블릿어플리케이션이기 때문에 포트를 알 수 있다. } }
Reference
https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto-embedded-web-servers
“How-to” Guides
Spring Boot has no mandatory logging dependency, except for the Commons Logging API, which is typically provided by Spring Framework’s spring-jcl module. To use Logback, you need to include it and spring-jcl on the classpath. The simplest way to do that is
docs.spring.io
'웹개발 > SpringBoot' 카테고리의 다른 글
3. 스프링 PSA (0) 2020.04.28 2. AOP(Aspect Oriented Programming) (0) 2020.04.10 1. IOC(Inversion of Controll) / DI(Depengency Injection) / Bean (0) 2020.04.05 내장 웹 서버 이해 (0) 2020.04.03