protected ApplicationContext initializeContext ( ) { Function < Class < Object > , List < Object > > getBeans = this :: getBeans ; BeanFactory beanFactory = new BeanFactory ( getBeans ) ; InitContext context = new InitContext ( ) ; AutoConfigurer . configureInitializers ( ) . forEach ( initializer -> initializer . init ( context , beanFactory ) ) ; List < AbstractReaderWriter > readersWriters = AutoConfigurer . configureReadersWriters ( ) ; ExceptionHandlerInterceptor exceptionHandlerInterceptor = new ExceptionHandlerInterceptor ( ) ; COMMON_INTERCEPTORS . add ( exceptionHandlerInterceptor ) ; Map < Boolean , List < Reader > > readers = createTransformers ( concat ( beanFactory . getAll ( Reader . class ) , context . getReaders ( ) , readersWriters ) ) ; Map < Boolean , List < Writer > > writers = createTransformers ( concat ( beanFactory . getAll ( Writer . class ) , context . getWriters ( ) , readersWriters ) ) ; List < Interceptor > interceptors = sort ( concat ( beanFactory . getAll ( Interceptor . class ) , context . getInterceptors ( ) , COMMON_INTERCEPTORS ) ) ; List < ExceptionConfiguration > handlers = concat ( beanFactory . getAll ( ExceptionConfiguration . class ) , context . getExceptionConfigurations ( ) , COMMON_HANDLERS ) ; List < ControllerConfiguration > controllers = concat ( beanFactory . getAll ( ControllerConfiguration . class ) , context . getControllerConfigurations ( ) ) ; orderDuplicationCheck ( interceptors ) ; Map < Class < ? extends Exception > , InternalExceptionHandler > handlerMap = handlers . stream ( ) . peek ( ExceptionConfiguration :: initialize ) . flatMap ( config -> config . getExceptionHandlers ( ) . stream ( ) ) . peek ( handler -> { populateHandlerWriters ( writers , handler , nonNull ( handler . getResponseType ( ) ) ) ; logExceptionHandler ( handler ) ; } ) . collect ( toMap ( InternalExceptionHandler :: getExceptionClass , identity ( ) ) ) ; context . setExceptionHandlers ( handlerMap ) ; controllers . stream ( ) . peek ( ControllerConfiguration :: initialize ) . flatMap ( config -> config . getRoutes ( ) . stream ( ) ) . peek ( route -> { route . interceptor ( interceptors . toArray ( new Interceptor [ interceptors . size ( ) ] ) ) ; populateRouteReaders ( readers , route ) ; populateRouteWriters ( writers , route ) ; logRoute ( route ) ; } ) . forEach ( context :: addRoute ) ; ApplicationContextImpl applicationContext = new ApplicationContextImpl ( ) ; applicationContext . setRoutes ( context . getRoutes ( ) ) ; applicationContext . setExceptionHandlers ( context . getExceptionHandlers ( ) ) ; exceptionHandlerInterceptor . setApplicationContext ( applicationContext ) ; return applicationContext ; }
Method causes the initialization of the application context using the methods which returns a collection of beans such as