当前位置: 首页 > news >正文

国外外贸网站大全wordpress插件 2017

国外外贸网站大全,wordpress插件 2017,wordpress有没有linux,宁波网站优化公司Bean的作用域 scope的属性值 属性值作用singleton默认单例prototype原型每调用一次getBean()方法则获取一个新的Bean对象 , 每次注入的时候都是新对象request一个请求对应一个Bean仅限于在WEB应用中使用 , 需要引入web的框架如SpringMvc(global) session一个会话对应一个Bean…

Bean的作用域

scope的属性值

属性值作用
singleton默认单例
prototype原型每调用一次getBean()方法则获取一个新的Bean对象 , 每次注入的时候都是新对象
request一个请求对应一个Bean仅限于在WEB应用中使用 , 需要引入web的框架如SpringMvc
(global) session一个会话对应一个Bean仅限于在WEB应用中使用 , 需要引入web的框架如SpringMvc
global sessionportlet应用中专用的, portlet和servlet都是规范, servlet运行在servlet容器中如Tomcat, portlet运行在portlet容器中
application一个应用对应一个Bean仅限于在WEB应用中使用
websocket一个websocket生命周期对应一个Bean仅限于在WEB应用中使用
自定义scope很少使用

scope属性值singleton(单例)

Spring的IoC容器中默认情况下Bean对象是单例的

  • Bean对象的创建是在初始化Spring上下文的时候就完成的 , 执行getBean()方法的时候Bean对象已经创建好了 , 每次获取操作的都是那个单例的Bean对象
public class SpringBean {public SpringBean() {System.out.println("SpringBean的无参数构造方法执行");}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"><!--默认情况下Bean对象是单例的,scope="singleton"可以省略--><bean id="sb" class="com.powernode.spring6.beans.SpringBean" />
</beans>
@Test
public void testScope(){ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring-scope.xml");SpringBean sb1 = applicationContext.getBean("sb", SpringBean.class);//com.powernode.spring6.beans.SpringBean@5b239d7dSystem.out.println(sb1);//com.powernode.spring6.beans.SpringBean@5b239d7dSpringBean sb2 = applicationContext.getBean("sb", SpringBean.class);System.out.println(sb2);
}

scope属性值prototype(多例)

如果想让Spring的Bean对象以多例的形式存在,可以在bean标签中指定scope属性的值为prototype

  • 初始化Spring上下文时不会创建这些prototype的Bean对象 , 只有每一次执行getBean()方法的时候才会创建,调用几次创建几次 , 每次获取的都是新的对象
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"><bean id="sb" class="com.powernode.spring6.beans.SpringBean" scope="prototype" />
</beans>
@Test
public void testScope(){ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring-scope.xml");//com.powernode.spring6.beans.SpringBean@29445a7SpringBean sb1 = applicationContext.getBean("sb", SpringBean.class);System.out.println(sb1);//com.powernode.spring6.beans.SpringBean@67d48005SpringBean sb2 = applicationContext.getBean("sb", SpringBean.class);System.out.println(sb2);
}

自定义线程级别Scope(了解)

第一步: 自定义Scope实现Scope接口,实现在同一个线程中获取的Bean都是同一个, 跨线程获取的是不同的Bean对象

  • Spring内置了实现Scope接口的线程范围的类org.springframework.context.support.SimpleThreadScope

第二步: 使用CustomScopeConfigurer内置类将自定义的Scope注册到Spring容器中

<bean class="org.springframework.beans.factory.config.CustomScopeConfigurer"><!--设置scopes属性,这个属性是个map集合表示可以指定多个线程范围--><property name="scopes"><map><!--自定义线程名--><entry key="myThread"><!--这个Scope接口的实现类使用的是Spring内置的,也可以自己定义--><bean class="org.springframework.context.support.SimpleThreadScope"/></entry></map></property>
</bean>

第三步: 使用自定义线程的Scope

<bean id="sb" class="com.powernode.spring6.beans.SpringBean" scope="myThread" />
@Test
public void testCustomScope(){//主线程ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring-scope.xml");SpringBean sb1 = applicationContext.getBean("sb", SpringBean.class);SpringBean sb2 = applicationContext.getBean("sb", SpringBean.class);//com.powernode.spring6.beans.SpringBean@5b236d7dSystem.out.println(sb1);//com.powernode.spring6.beans.SpringBean@5b236d7dSystem.out.println(sb2);// 启动新线程new Thread(new Runnable() {@Overridepublic void run() {SpringBean a = applicationContext.getBean("sb", SpringBean.class);SpringBean b = applicationContext.getBean("sb", SpringBean.class);//com.powernode.spring6.beans.SpringBean@29445a6System.out.println(a);//com.powernode.spring6.beans.SpringBean@29445a6System.out.println(b);}}).start();
}
http://www.yayakq.cn/news/566422/

相关文章:

  • 上海自适应网站制作网站开发前台与后台的交互
  • 哪里买到纯净网站模板制作网站好的公司
  • 电脑上做网站江津区网站建设
  • 只做百度移动端网站可以吗黄金外汇网站建设
  • 研磨材料 东莞网站建设苏州调查公司电话
  • 做淘宝一件代发的网站搜狗网站排名怎么做
  • 怎样增加网站的权重门户网站制作费用
  • 长沙做网站找哪家好wordpress 置顶排序
  • 网站内部优化php开发网站建设
  • 学网站建设工作公司网站建设多少费用济南兴田德润评价
  • 网站式的公司记录怎么做如何设计好网站
  • 做网站优化有必要爱站网关键词长尾挖掘
  • 自己的域名可以转给做网站的账号吗网站建设教程学校
  • 全屏响应式网站模板怎么在百度制作自己的网站
  • 建设人力资源服务网站工作方案wordpress paginate_links
  • 网站是先解析后备案吗wordpress mo主题
  • 广东宏昌建设有限公司网站国际新闻最新消息今天军事新闻
  • 建立网站ftp房产网签合同
  • 兰州网站建设哪家公司好广州一网通办注册公司流程
  • 技术成果交易网站建设方案求网站晚上睡不着2021
  • 做个网站一般多少钱建立网站信息发布登记制度
  • 公司网页设计费计入什么科目关键词的优化和推广
  • 网站建设和谷歌优化网络环境搭建
  • 学校网站建设的技术方案亚马逊seo推广
  • 永久网站徐州做企业网站
  • 合肥做的比较好的网站有那几家人武部正规化建设的意义
  • dede发布网站网站专题设计模板
  • 二级网站怎样被百度收录毕设做桌面端还是网站
  • 一个网站占空间有多少g手机网站域名绑定
  • 如何用文档创建一个网站搭建一个网站大概需要多少钱