星空网 > 软件开发 > ASP.net

Spring 一二事(4)

 

spring bean配置后再默认情况下是单例的,如果需要配置可以选择 prototype, request, session和global session

在配置spring mvc的action时,可以对action使用 prototype

1    <!-- singleton: 默认单例 prototype: 多例 request ,session和global session: 只适用于web程序 -->2   <bean id="scope_prototype" class="com.lee.spring005.scope.Scope"3     scope="prototype"></bean>4 5   <!-- destroy-method 一般在数据源的时候用到,关闭容易后就销毁连接 -->6   <bean id="initDestory" class="com.lee.spring006.init_destory.InitDestory"7     init-method="init" destroy-method="destory"></bean>

bean的创建销毁过程:

 1 package com.lee.spring006.init_destory; 2  3 public class InitDestory { 4  5   public InitDestory() { 6     System.out.println("InitDestory() "); 7   } 8  9   public void hello() {10     System.out.println("Hello InitDestory!");11   }12   13   public void init() {14     System.out.println("init");15   }16   17   public void destory() {18     System.out.println("destory");19   }20 }

测试:

 1   @Test 2   public void testInitDestory() { 3  4     ApplicationContext context = new ClassPath); 5      6     InitDestory initDestory = (InitDestory)context.getBean("initDestory"); 7     initDestory.hello(); 8      9     ClassPath (ClassPath10     app.close();11   }

 github地址:https://github.com/leechenxiang/maven-spring001-helloworld




原标题:Spring 一二事(4)

关键词:Spring

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

金宏亚物流:https://www.goluckyvip.com/tag/34742.html
金泓跨境:https://www.goluckyvip.com/tag/34743.html
金华fba头程物流:https://www.goluckyvip.com/tag/34744.html
金华电商培训:https://www.goluckyvip.com/tag/34745.html
金华物流专线:https://www.goluckyvip.com/tag/34747.html
金华专线物流:https://www.goluckyvip.com/tag/34748.html
商机!速卖通推出小B采销节,挖掘机、莫桑钻、电动车近期在海外走俏!:https://www.xlkjsw.com/news/93297.html
Zalando对欧盟在线平台监管费提出质疑:https://www.kjdsnews.com/a/1842241.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流