Spring入门篇之Bean的配置项及作用域
2016-12-02 10:58
387 查看
1.Bean的配置项:
2.Bean的作用域:
例子:
从测试中的结果我们就可以看到是否该容器中存在的是同一个实例的bean
2.Bean的作用域:
例子:
package com.wuyonghu.insert; public class BeanScope { public void printMes(String meString){ System.out.println("参数的数据是:"+meString); } }
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"> <bean id="beanScope" class="com.wuyonghu.insert.BeanScope" scope="prototype"></bean> </beans>
@Test public void testHello4() { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml"); BeanScope bean = (BeanScope) context.getBean("beanScope"); BeanScope bean1 = (BeanScope) context.getBean("beanScope"); System.out.println(bean==bean1); }
从测试中的结果我们就可以看到是否该容器中存在的是同一个实例的bean
相关文章推荐
- Spring入门篇之Bean的配置项及作用域
- Spring学习笔记(5.Spring Bean装配之Bean的配置项及作用域)
- Spring入门(Bean配置项、生命周期等)
- Spring Bean的配置项:作用域与生命周期
- Spring Bean的配置项及作用域
- Spring Bean--Bean的配置项、作用域、生命周期
- 那些年、一起追过的Spring--(3)----Bean的配置项及作用域,Bean装配的生命周期,配置集合对象
- Spring入门(3)-Spring命名空间与Bean作用域
- Spring入门——Spring Bean装配之Bean的配置项
- Spring配置中 bean上的属性parent的作用
- 容器对象spring(4)_ bean属性 scope:作用域和lazy-init
- spring入门(4)---spring中Bean的生命周期总结
- spring入门(8)--装配Bean之自动装配
- 注入参数spring入门(7)---装配Bean中构造参数的注入
- spring心得1--spring入门介绍@bean的加载初讲@第一个spring项目helloWord
- Spring中bean作用域属性scope
- spring心得2--bean的生命周期@Spring监听器的作用@Spring初始化容器案例分析@web项目使用
- spring心得2--bean的生命周期@Spring监听器的作用@Spring初始化容器案例分析@web项目使用
- Spring注入非单例bean以及scope的作用范围
- Spring Bean的5种作用域