注意: I. class 指向的是静态工厂类; II. factory-method 配置的是静态工厂方法中的方法; III. 若静态方法需要传入参数,则使用 <constructor-arg value="ford"></constructor-arg> 方式传入参数
2). 使用实例工厂方法来配置 bean
public class InstanceCarFactory { private Map<String, Car> cars = new HashMap<String, Car>(); public InstanceCarFactory() { cars.put("ford", new Car("ford", "ChangAn", 200000, 200)); cars.put("mazda", new Car("Mazda", "ChangAn", 210000, 210)); } public Car get(String brand){ return cars.get(brand); } }