1 16 17 package org.springframework.beans.factory.config; 18 19 import org.springframework.beans.BeansException; 20 import org.springframework.beans.factory.BeanFactory; 21 import org.springframework.beans.factory.BeanFactoryAware; 22 import org.springframework.beans.factory.ObjectFactory; 23 import org.springframework.util.Assert; 24 25 96 public class ObjectFactoryCreatingFactoryBean extends AbstractFactoryBean 97 implements BeanFactoryAware { 98 99 private String targetBeanName; 100 101 private BeanFactory beanFactory; 102 103 104 115 public void setTargetBeanName(String targetBeanName) { 116 this.targetBeanName = targetBeanName; 117 } 118 119 public void setBeanFactory(BeanFactory beanFactory) { 120 this.beanFactory = beanFactory; 121 } 122 123 protected Object createInstance() { 124 return new ObjectFactory() { 125 public Object getObject() throws BeansException { 126 return beanFactory.getBean(targetBeanName); 127 } 128 }; 129 } 130 131 public void afterPropertiesSet() throws Exception { 132 Assert.hasText(targetBeanName, "targetBeanName is required"); 133 super.afterPropertiesSet(); 134 } 135 136 public Class getObjectType() { 137 return ObjectFactory.class; 138 } 139 140 } 141 | Popular Tags |