描述:当通过getBean()方法请求该Bean时,Spring是根据Bean的作用域决定应该返回的Bean实例。默认的作用域为singleton,意思是每个Spring IoC容器只创建一个Bean实例。但在某些情况下,这样的作用域并不合适,比如购物车,应该是每请求一次就创建一次Bean实例。因此,需要为Bean设置更合适的Bean的作用域。例子:购物车ShoppingCart类:package chapter4_1;import java.util.ArrayList;import java.util.List;public class ShoppingCart { private ... Read More
posted @ 2013-04-01 22:01 爱生活者wmmang Views(286) Comments(0) Diggs(0) Edit
描述:在Spring IoC容器中,可能希望根据对象属性来声明Bean。比如:ProductRanking类中存在属性Product,那么在配置文件中声明ProductRanking时,对于内部属性Product很可能是采用内部Bean的方式来声明的。此时可以利用Spring内置的工厂BeanPropertyPathFactoryBean获取它了.例子:在ProductRanking类:package chapter3_7;public class ProductRanking { private Produce producte; public Produce getProduc... Read More
posted @ 2013-04-01 21:32 爱生活者wmmang Views(163) Comments(0) Diggs(0) Edit