1. 工厂实例方法创建对象是指Ioc容器对工厂类进行实例化,并调用对应的实例方法创建对象的过程
2. src/main/java/com/imooc/spring/ioc/factory/AppleFactoryInstance.java
package com.imooc.spring.ioc.factory; import com.imooc.spring.ioc.entity.Apple; /** * 工厂实例方法创建对象是指Ioc容器对工厂类进行实例化并调用对应的实例方法创建对象的过程 */ public class AppleFactoryInstance { public Apple createSweetApple() { Apple apple = new Apple(); apple.setTitle("红富士"); apple.setOrigin("欧洲"); apple.setColor("红色"); return apple; } }
3. src/main/resources/applicationContext.xml
<!--利用工厂实例化方法获取对象--> <bean id="factoryInstance" class="com.imooc.spring.ioc.factory.AppleFactoryInstance"/> <bean id="apple5" factory-bean="factoryInstance" factory-method="createSweetApple"/>
标签:基于,apple,spring,创建对象,工厂,实例,Apple From: https://www.cnblogs.com/LLL0617/p/16913885.html