001/* 002 * Copyright 2002-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.context; 018 019/** 020 * Callback interface for initializing a Spring {@link ConfigurableApplicationContext} 021 * prior to being {@linkplain ConfigurableApplicationContext#refresh() refreshed}. 022 * 023 * <p>Typically used within web applications that require some programmatic initialization 024 * of the application context. For example, registering property sources or activating 025 * profiles against the {@linkplain ConfigurableApplicationContext#getEnvironment() 026 * context's environment}. See {@code ContextLoader} and {@code FrameworkServlet} support 027 * for declaring a "contextInitializerClasses" context-param and init-param, respectively. 028 * 029 * <p>{@code ApplicationContextInitializer} processors are encouraged to detect 030 * whether Spring's {@link org.springframework.core.Ordered Ordered} interface has been 031 * implemented or if the @{@link org.springframework.core.annotation.Order Order} 032 * annotation is present and to sort instances accordingly if so prior to invocation. 033 * 034 * @author Chris Beams 035 * @since 3.1 036 * @param <C> the application context type 037 * @see org.springframework.web.context.ContextLoader#customizeContext 038 * @see org.springframework.web.context.ContextLoader#CONTEXT_INITIALIZER_CLASSES_PARAM 039 * @see org.springframework.web.servlet.FrameworkServlet#setContextInitializerClasses 040 * @see org.springframework.web.servlet.FrameworkServlet#applyInitializers 041 */ 042public interface ApplicationContextInitializer<C extends ConfigurableApplicationContext> { 043 044 /** 045 * Initialize the given application context. 046 * @param applicationContext the application to configure 047 */ 048 void initialize(C applicationContext); 049 050}