package com.tanlei.bean.FactoryBean;

import org.springframework.beans.factory.FactoryBean;

public class CarFactoryBean  implements FactoryBean<Car>{

    private String brand;

    public void setBrand(String brand) {
this.brand = brand;
} //返回bean的对象
@Override
public Car getObject() throws Exception {
// TODO Auto-generated method stub
return new Car(brand,500000);
} /**
* 返回Bean的类型
*/
@Override
public Class<?> getObjectType() {
// TODO Auto-generated method stub
return Car.class;
} @Override
public boolean isSingleton() {
// TODO Auto-generated method stub
return true;
} }

//自定义的FactoryBean需要实现FactoryBean接口

<!--
通过FactoryBean来配置Bean的实例
class:指向FactoryBean的全类名
property:配置的是FactoryBean的属性,但实际返回的实例是FactoryBean的getObject()方法返回的实例
-->

Spring_通过Bean的Factory配置Bean-LMLPHP

05-28 07:49