org.springframework.beans.factory.config.FieldRetrievingFactoryBean Maven / Gradle / Ivy
/*
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.beans.factory.config;
import java.lang.reflect.Field;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.FactoryBeanNotInitializedException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;
/**
* {@link FactoryBean} which retrieves a static or non-static field value.
*
* Typically used for retrieving public static final constants. Usage example:
*
*
* // standard definition for exposing a static field, specifying the "staticField" property
* <bean id="myField" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
* <property name="staticField" value="java.sql.Connection.TRANSACTION_SERIALIZABLE"/>
* </bean>
*
* // convenience version that specifies a static field pattern as bean name
* <bean id="java.sql.Connection.TRANSACTION_SERIALIZABLE"
* class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean"/>
*
*
* If you are using Spring 2.0, you can also use the following style of configuration for
* public static fields.
*
*
<util:constant static-field="java.sql.Connection.TRANSACTION_SERIALIZABLE"/>
*
* @author Juergen Hoeller
* @since 1.1
* @see #setStaticField
*/
public class FieldRetrievingFactoryBean
implements FactoryBean