11package com .baeldung .web .log .app ;
22
3- import javax .servlet .ServletContext ;
4- import javax .servlet .ServletException ;
53import javax .servlet .ServletRegistration ;
64
75import org .springframework .boot .SpringApplication ;
86import org .springframework .boot .autoconfigure .EnableAutoConfiguration ;
97import org .springframework .boot .autoconfigure .SpringBootApplication ;
108import org .springframework .context .annotation .ComponentScan ;
11- import org .springframework .web .context .ContextLoaderListener ;
12- import org .springframework .web .context .support .AnnotationConfigWebApplicationContext ;
13- import org .springframework .web .servlet .DispatcherServlet ;
149import org .springframework .context .annotation .PropertySource ;
1510
1611import com .baeldung .web .log .config .CustomeRequestLoggingFilter ;
1712
18- import org .springframework .boot .web .servlet .support .SpringBootServletInitializer ;
19-
2013@ EnableAutoConfiguration
2114@ ComponentScan ("com.baeldung.web.log" )
2215@ PropertySource ("application-log.properties" )
2316@ SpringBootApplication
24- public class Application extends SpringBootServletInitializer {
17+ public class Application {
2518
2619 public static void main (final String [] args ) {
2720 SpringApplication .run (Application .class , args );
2821 }
29-
30- @ Override
31- public void onStartup (ServletContext container ) throws ServletException {
32-
33- AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext ();
34- context .setConfigLocation ("com.baeldung.web.log" );
35- container .addListener (new ContextLoaderListener (context ));
36-
37- ServletRegistration .Dynamic dispatcher = container .addServlet ("dispatcher" , new DispatcherServlet (context ));
38- dispatcher .setLoadOnStartup (1 );
39- dispatcher .addMapping ("/" );
40-
41- container .addFilter ("customRequestLoggingFilter" , CustomeRequestLoggingFilter .class ).addMappingForServletNames (null , false , "dispatcher" );
42- }
4322}
0 commit comments