标签:
1 <?xml version="1.0" encoding="UTF-8"?>
2 <beans
3 xmlns="http://www.springframework.org/schema/beans"
4 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5 xmlns:context="http://www.springframework.org/schema/context"
6 xsi:schemaLocation=
7 "http://www.springframework.org/schema/beans
8 http://www.springframework.org/schema/beans/spring-beans.xsd
9 http://www.springframework.org/schema/context
10 http://www.springframework.org/schema/context/spring-context.xsd">
11
12 <bean id="discount" class="com.wzh.service.impl.Discout"></bean>
13 <bean id="discount" class="com.wzh.service.impl.Discout11"></bean>
14 <bean id="discount" class="com.wzh.service.impl.Discout12"></bean>
15
16 </beans>
public void pay(List<Goods> goods){
//初始化IOC容器的代码
ApplicationContext ac = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
IDiscout discout = (IDiscout)ac.getBean("discount");
Float total = discout.discout(goods);
System.out.println("向支付宝发发起" + total + "元支付请求");
}
5. 设置延迟加载lazy-init="true"
是指需要用的(第一次调用getBean())时候才会创建对象,懒加载在多例模式下无效,且多次调用的时候都指向相同的对象.
标签:
原文地址:http://www.cnblogs.com/buibui/p/5803468.html