Spring Factory Bean
<!--
通过FactoryBean来配置Bean的实例
class:指向FactoryBean的全类名
property:配置FactoryBean的属性
但实际返回的实例却是FactoryBean的getObject()方法返回的实例
-->
<bean id="dog" class="com.metadata.factorybean.DogFactory">
<property name="name" value="kk"></property>
</bean>
public class DogFactory implements FactoryBean<Dog>{
private String name;
public void setName(String name) {
this.name = name;
}
//返回Bean的对象
@Override
public Dog getObject() throws Exception {
// TODO Auto-generated method stub
//return new Dog("dd", "blue");
return new Dog(name, "green");
}
//返回Bean的类型
@Override
public Class<?> getObjectType() {
return Dog.class;
}
//是否单例
@Override
public boolean isSingleton() {
return true;
}
}