본문 바로가기

Spring

SpringBootServletInitializer 란 무엇일까? 왜쓰지?

728x90
반응형

차근차근 공부하려고 했는데 모르는게 너무 많다.

다소 번잡스럽지만 최대한 정리를 해가면서 업무를 하려고 일단 찾아본 대로 정리한다.

 

SpringBootServletInitializer란?

더보기

An opinionated WebApplicationInitializer to run a SpringApplication from a traditional WAR deployment. Binds Servlet, Filter and ServletContextInitializer beans from the application context to the server.

To configure the application either override the configure(SpringApplicationBuilder) method (calling SpringApplicationBuilder.sources(Class...)) or make the initializer itself a @Configuration. If you are using SpringBootServletInitializer in combination with other WebApplicationInitializers you might also want to add an @Ordered annotation to configure a specific startup order.

가져와봤다.

war배포할 때 SpringBoot에서 필요한 WebApplicationInitializer라고 한다.

애플리케이션 컨텍스트에서 서버로 서블릿, 필터, 서블릿컨텍스트 이니셜라이저 빈들을 바인드한다.

 

즉, 옛날에는 내장 톰캣을 쓰지 않았을 때 

web.xml에 dispatcher servlet을 등록해줬는데 

이런 작업은 결국 스프링을 서블릿 컨테이너에서 동작하도록 하기 위함이다.

 

Setvlet 3.0 스펙 중 하나가 web.xml이 없이도 배포가 가능해진 것인데 

톰캣 7부터 지원한다고 한다.

 

뭐, 아무튼 서블릿컨테이너에서(톰캣과 같은) SpringBoot 애플리케이션이 

동작하도록 웹 어플리케이션 컨텍스트를 구성한다는 얘기다.

@SpringBootApplication
public class Application extends SpringBootServletInitializer {
 
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }
 
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
 
}

configure를 오버라이딩 하면 된다.

 

docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto-traditional-deployment

728x90
반응형