001/* 002 * Copyright 2002-2017 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; 018 019import org.springframework.beans.BeansException; 020 021/** 022 * Defines a factory which can return an Object instance 023 * (possibly shared or independent) when invoked. 024 * 025 * <p>This interface is typically used to encapsulate a generic factory which 026 * returns a new instance (prototype) of some target object on each invocation. 027 * 028 * <p>This interface is similar to {@link FactoryBean}, but implementations 029 * of the latter are normally meant to be defined as SPI instances in a 030 * {@link BeanFactory}, while implementations of this class are normally meant 031 * to be fed as an API to other beans (through injection). As such, the 032 * {@code getObject()} method has different exception handling behavior. 033 * 034 * @author Colin Sampaleanu 035 * @since 1.0.2 036 * @see FactoryBean 037 */ 038public interface ObjectFactory<T> { 039 040 /** 041 * Return an instance (possibly shared or independent) 042 * of the object managed by this factory. 043 * @return the resulting instance 044 * @throws BeansException in case of creation errors 045 */ 046 T getObject() throws BeansException; 047 048}