day38 08-Spring的id、name和scope顺序
访问的路径的是/login.id不允许出现特殊的字符。/是特殊的字符。Struts 2已经没有/,action的名字已经不带/了。现在的开发中一般使用id这个属性即可。
这个类在被Spring创建的时候是一个单例的还是一个多例的?
reuqest和session都是在web开发中使用.它们的区别是web的域不同.
package cn.itcast.spring3.demo3; import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; /**
* Bean的作用范围
* @author zhongzh
*
*/ public class SpringTest3 {
@Test
public void demo1(){
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
//这是工厂对象
Customer c1 = (Customer) applicationContext.getBean("customer");
System.out.println(c1); Customer c2 = (Customer) applicationContext.getBean("customer");
System.out.println(c2);
//如果c1和c2的地址一样,那么它只被实例化一次 } }
package cn.itcast.spring3.demo3; public class Customer { public Customer() {
super();
System.out.println("Customer类被实例化.........");
} }
<?xml version="1.0" encoding="UTF-8"?>
<!-- 别去schema,schema是文件,本地的文件,你得引那个头 --> <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">
<!-- demo1快速入门================================================= -->
<!-- 把接口和实现类在这个配置文件中配置,有了实现类的全路径之后到时候才能用工厂反射 --> <!-- 通过一个<bean>标签来设置类的信息,通过id属性为类起个标识. -->
<!-- 接口,实现类,配置文件也都有了 -->
<!-- 现在有一个工厂Spring为我们提供好了,其实就是解析这个XML文件 -->
<!-- 这个工厂你自己写会不会写?你用dom4j找里面的bean标签,找到class的属性值,然后就可以Class.forName()反射生成类的实例.其实Spring
也是这么做的,只不过工厂由Spring提供好了
-->
<bean id="helloService" class="cn.itcast.spring3.demo1.HelloServiceImpl">
<!-- 使用<property>标签注入属性
value指的是普通值
ref指的是对象
-->
<property name="info" value="传智播客"></property>
</bean>
<!-- demo1快速入门 -->
<!-- demo2Bean的实例化 -->
<!-- 默认情况下使用的就是无参数的构造方法. -->
<!--
<bean id="bean1" class="cn.itcast.spring3.demo2.Bean1"></bean>
-->
<bean name="bean1" class="cn.itcast.spring3.demo2.Bean1"></bean>
<!-- 第二种使用静态工厂实例化 不能写class了,因为现在不是由Spring直接帮你创建对象了-->
<bean id="bean2" class="cn.itcast.spring3.demo2.Bean2Factory" factory-method="getBean2"></bean>
<!-- 第三种使用实例工厂实例化 -->
<bean id="bean3" factory-bean="bean3Factory" factory-method="getBean3"></bean>
<!-- 要先把Bean3Factory实例化 -->
<bean id="bean3Factory" class="cn.itcast.spring3.demo2.Bean3Factory"></bean>
<!-- demo2Bean的实例化====================== end--> <!-- demo3Bean的作用范围======================= -->
<bean id="customer" class="cn.itcast.spring3.demo3.Customer" scope="prototype">
</bean>
</beans>
这就是bean的id和scope这几个属性。如果是scope="prototype",那么被获取多次就被实例化多次;如果是scope="singleton",那么被获取多次也只被实例化一次。
day38 08-Spring的id、name和scope顺序的更多相关文章
- struts+spring action应配置为scope="prototype"
truts+spring action应配置为scope="prototype" <bean id="personAction" scope=" ...
- dubbo spring bean id冲突
service-security-provider应用有provider和consumer配置文件 其中secutrity-consumer引用两个服务 <dubbo:reference int ...
- Duplicate spring bean id
问题背景:从本地调用服务器的dubbo接口进行测试 实现思路:基于IDEA+Spring+maven+Dubbo搭建测试项目,从本地直接调用 具体实现思路可参考博客:https://www.cnb ...
- Spring Security 入门(1-6-2)Spring Security - 内置的filter顺序、自定义filter、http元素和对应的filterChain
Spring Security 的底层是通过一系列的 Filter 来管理的,每个 Filter 都有其自身的功能,而且各个 Filter 在功能上还有关联关系,所以它们的顺序也是非常重要的. 1.S ...
- spring多个AOP执行先后顺序(面试问题:怎么控制多个aop的执行循序)
转载:spring多个AOP执行先后顺序(面试问题:怎么控制多个aop的执行循序) 众所周知,spring声明式事务是基于AOP实现的,那么,如果我们在同一个方法自定义多个AOP,我们如何指定他们的执 ...
- Spring Boot的属性加载顺序
伴随着团队的不断壮大,往往不需要开发人员知道测试或者生产环境的全部配置细节,比如数据库密码,帐号信息等.而是希望由运维或者指定的人员去维护配置信息,那么如果要修改某项配置信息,就不得不去修改项 ...
- spring之bean的作用域scope的值的详解
今天研究了一下scope的作用域.默认是单例模式,即 scope="singleton".另外scope还有prototype.request.session.global ses ...
- spring bean id重复覆盖的问题解决
问题: 当我们的web应用做成一个大项目之后,里面有很多的bean配置,如果两个bean的配置id是一样的而且实现类也是一样的,例如有下面两份xml的配置文档: beancontext1.xml &l ...
- 08.Spring Bean 解析 - BeanDefinitionDocumentReader
基本概念 BeanDefinitionDocumentReader ,该类的作用有两个,完成 BeanDefinition 的解析和注册 . 解析:其实是解析 Ddocument 的内容并将其添加到 ...
随机推荐
- mac下安装Python的工具包pip
1. 在终端下输入 sudo easy_install pip password:输入电脑密码 Finished processing dependencies for pip 表示安装完成 boe ...
- HLog工作原理
- rabbitmq类
1.accept.php消费者代码需要在命令行执行 2.'username'=>'asdf','password'=>'123456' 改成自己的帐号和密码 RabbitMQCommand ...
- [Swoole系列入门教程 5] UDP协议和demo
• 客户端服务端没有任何联系 • 指定地址跟端口,不关心消息是否发送成功 • 心跳检测不能影响到客户端• udp建立长连接
- Python开发第三方必备工具
<wiz_tmp_tag id="wiz-table-range-border" contenteditable="false" style=&quo ...
- css的层叠性+继承性+优先级+权重
一.层叠性 1.含义 多种css样式叠加,浏览器处理冲突的能力. 2.原则 1>一般情况下,若出现冲突,会按照css的书写顺序,以最后的样式为准 2>样式不冲突,就不会层叠 二.css的继 ...
- JS实现数据双向绑定
本文参考https://www.cnblogs.com/tianhaining/p/8425345.html 首先先说个面试题哈,就是vue中的v-model是如何实现双向数据绑定的咳咳,下面开始背诵 ...
- 在Bat批处理中调用Powershell脚本
##如何在BAT中调用powershell,把下面代码另存为bat格式pushd %~dp0powershell.exe -command ^ "& {set-executionp ...
- mysql中的字符集和校对规则(mysql校对集)
1.简要说明介绍 字符集和校对规则 字符集是一套符号和编码.校对规则是在字符集内用于比较字符的一套规则. MySql在collation提供较强的支持,oracel在这方面没查到相应的资料. 不同字符 ...
- python初学小记
使用PyCharm向世界打招呼! print (“Hello world!”) 介绍自己的基本信息的方法 name = input("name:")age = int(input( ...