001/* 002 * Copyright 2002-2019 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.beans.factory.config; 018 019import org.springframework.beans.BeansException; 020 021/** 022 * Factory hook that allows for custom modification of an application context's 023 * bean definitions, adapting the bean property values of the context's underlying 024 * bean factory. 025 * 026 * <p>Useful for custom config files targeted at system administrators that 027 * override bean properties configured in the application context. See 028 * {@link PropertyResourceConfigurer} and its concrete implementations for 029 * out-of-the-box solutions that address such configuration needs. 030 * 031 * <p>A {@code BeanFactoryPostProcessor} may interact with and modify bean 032 * definitions, but never bean instances. Doing so may cause premature bean 033 * instantiation, violating the container and causing unintended side-effects. 034 * If bean instance interaction is required, consider implementing 035 * {@link BeanPostProcessor} instead. 036 * 037 * <h3>Registration</h3> 038 * <p>An {@code ApplicationContext} auto-detects {@code BeanFactoryPostProcessor} 039 * beans in its bean definitions and applies them before any other beans get created. 040 * A {@code BeanFactoryPostProcessor} may also be registered programmatically 041 * with a {@code ConfigurableApplicationContext}. 042 * 043 * <h3>Ordering</h3> 044 * <p>{@code BeanFactoryPostProcessor} beans that are autodetected in an 045 * {@code ApplicationContext} will be ordered according to 046 * {@link org.springframework.core.PriorityOrdered} and 047 * {@link org.springframework.core.Ordered} semantics. In contrast, 048 * {@code BeanFactoryPostProcessor} beans that are registered programmatically 049 * with a {@code ConfigurableApplicationContext} will be applied in the order of 050 * registration; any ordering semantics expressed through implementing the 051 * {@code PriorityOrdered} or {@code Ordered} interface will be ignored for 052 * programmatically registered post-processors. Furthermore, the 053 * {@link org.springframework.core.annotation.Order @Order} annotation is not 054 * taken into account for {@code BeanFactoryPostProcessor} beans. 055 * 056 * @author Juergen Hoeller 057 * @author Sam Brannen 058 * @since 06.07.2003 059 * @see BeanPostProcessor 060 * @see PropertyResourceConfigurer 061 */ 062@FunctionalInterface 063public interface BeanFactoryPostProcessor { 064 065 /** 066 * Modify the application context's internal bean factory after its standard 067 * initialization. All bean definitions will have been loaded, but no beans 068 * will have been instantiated yet. This allows for overriding or adding 069 * properties even to eager-initializing beans. 070 * @param beanFactory the bean factory used by the application context 071 * @throws org.springframework.beans.BeansException in case of errors 072 */ 073 void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException; 074 075}