Spring1 Bean实例化
来源:互联网 发布:台电x16 plus淘宝 编辑:程序博客网 时间:2024/06/08 09:06
1. Bean实例化的方法
a. 普通方法
b. 静态工厂方法
c. 工厂方法
a. 普通方法
public class PersonServiceBean implements PersonService {public void save(){System.out.println("我是save()方法");}}
<bean id="personService" class="cn.itcast.service.impl.PersonServiceBean"></bean>
@Test public void instanceSpring(){ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");PersonService personService = (PersonService)ctx.getBean("personService");personService.save();}
b. 静态工厂方法
public class PersonServiceBeanFactory {public static PersonServiceBean createPersonServiceBean(){return new PersonServiceBean();}}
<bean id="personService2" class="cn.itcast.service.impl.PersonServiceBeanFactory" factory-method="createPersonServiceBean"/>
@Test public void instanceSpring(){ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");PersonService personService = (PersonService)ctx.getBean("personService2");personService.save();}
c. 工厂方法
public class PersonServiceBeanFactory {public PersonServiceBean createPersonServiceBean2(){return new PersonServiceBean();}}
<bean id="personServiceFactory" class="cn.itcast.service.impl.PersonServiceBeanFactory"/> <bean id="personService3" factory-bean="personServiceFactory" factory-method="createPersonServiceBean2"/>
@Test public void instanceSpring(){ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");PersonService personService = (PersonService)ctx.getBean("personService3");personService.save();}
阅读全文
0 0
- Spring1 Bean实例化
- Spring1.2——bean相关
- Spring1
- spring1
- spring1
- Spring1
- Spring1
- spring1
- spring1
- Spring1
- Spring1
- spring1
- 预实例化Bean
- Spring 实例化bean
- spring实例化bean
- 实例化bean
- Springframework实例化Bean
- Bean实例化问题
- meanshift算法通俗讲解
- spring 3.0 应用springmvc 构造RESTful URL 详细讲解
- 找出1~n之间的所有素数
- 数据挖掘RapidMiner工具使用----产品介绍与安装过程
- hdu2844—Coins(多重背包)
- Spring1 Bean实例化
- angularjs指令中的compile与link函数详解
- spring2 bean作用域 和 生命周期
- 各种常用的排序算法实现对数组的排序——整理总结(代码实现)
- JVM的内存模型
- $GLOBALS['HTTP_RAW_POST_DATA'] 和$_POST的区别
- java 中获取各种路径
- Spark Streaming
- 徐飞玉:自然语言理解及其应用学习笔记