1、可以从ApplicationContext上下文获取和bean工厂获取容器,bean工厂只建议在移动端应用使用。

2、如果使用的是applicationContext配置的是bean,如果作用域是singleton,不管你使不使用都会被实例化。(好处是预先加载,欠缺点是耗内存)

3、如果是FactoryBean,则当实例化对象的时候,不会马上实例化bean,使用的时候才会实例化。(好处是节约内存,缺点速度慢)

4、bean作用域

强调一点:尽量使用scope=singleton,不要使用prototype,因为这样会对性能造成影响。

5、bean的装配

三种获取ApplicationContextCD的方法:

①ClassPathXmlApplicationContext  通过路径

②FileSystemXmlApplicationContext通过文件路径

③XmlWebApplicationContext从web系统加载。

6、给集合注入属性

①数组

 <property name="empName">
<list>
<value>小明</value>
<value>小红</value>
<value>小化</value>
</list>
</property>
②list
<property name="empList">
<list>
<ref bean="emp1" />
<ref bean="emp2" />
<ref bean="emp3" />
</list>
</property>
③set
 <property name="empSet">
<set>
<ref bean="emp1" />
<ref bean="emp2" />
<ref bean="emp3" />
</set>
</property>
④Map
 <property name="empMap">
<map>
<entry key="11" value-ref="emp1"></entry>
<entry key="22" value-ref="emp2"></entry>
<entry key="33" value-ref="emp3"></entry>
</map>
</property>
</bean>
<bean id="emp1" class="com.Collection.Employee">
<property name="name" value="北京" />
<property name="id" value="1"></property>
</bean>
<bean id="emp2" class="com.Collection.Employee">
<property name="name" value="天津" />
<property name="id" value="2"></property>
</bean>
<bean id="emp3" class="com.Collection.Employee">
<property name="name" value="上海" />
<property name="id" value="3"></property>
</bean>

⑤继承

<bean id="student" class="com.inherit.Student">
<property name="name" value="xiaoming"></property>
<property name="age" value="22"></property>
</bean>
<bean id="graduate" parent="student" class="com.inherit.Graduate" >
<property name="degree" value="博士"></property>
</bean>
7、通过构造函数来注入
<bean id="employee" class="com.Construct.Employee" >
<constructor-arg index="0" type="java.lang.String" value="xiaohong"></constructor-arg>
<constructor-arg index="1" type="int" value="21"></constructor-arg>
</bean>
8、自动装配

①byName

<bean id="dog" class="com.autowire.Dog" >
<property name="name" value="大黄"></property>
<property name="age" value="3"></property>
</bean>
<bean id="master" class="com.autowire.Master" autowire="byName">
<property name="name" value="鸣人"></property>
</bean>
②byType
<bean id="dog12" class="com.autowire.Dog" >
<property name="name" value="大黄"></property>
<property name="age" value="3"></property>
</bean>
<bean id="master" class="com.autowire.Master" autowire="byType">
<property name="name" value="鸣人"></property>
</bean>

③constructor

<bean id="dog12" class="com.autowire.Dog" >
<property name="name" value="大黄"></property>
<property name="age" value="3"></property>
</bean>
<bean id="master" class="com.autowire.Master" autowire="constructor">
<property name="name" value="鸣人"></property>
</bean>

Bean的装配的更多相关文章

  1. Spring bean依赖注入、bean的装配及相关注解

    依赖注入 Spring主要提供以下两种方法用于依赖注入 基于属性Setter方法注入 基于构造方法注入 Setter方法注入 例子: public class Communication { priv ...

  2. Spring学习记录(三)---bean自动装配autowire

    Spring IoC容器可以自动装配(autowire)相互协作bean之间的关联关系,少写几个ref autowire: no ---默认情况,不自动装配,通过ref手动引用 byName---根据 ...

  3. Spring4学习笔记 - 配置Bean - 自动装配 关系 作用域 引用外部属性文件

    1 Autowire自动装配 1.1 使用:只需在<bean>中使用autowire元素 <bean id="student" class="com.k ...

  4. Spring - 配置Bean - 自动装配 关系 作用域 引用外部属性文件

    1 Autowire自动装配1.1 使用:只需在<bean>中使用autowire元素<bean id="student" class="com.kej ...

  5. spring2——IOC之Bean的装配

    spring容器对于bean的装配提供了两个接口容器分别是"ApplicationContext接口容器"和"BeanFactory接口容器",其中" ...

  6. Spring温故而知新 - bean的装配(续)

    按条件装配bean 就是当满足特定的条件时Spring容器才创建Bean,Spring中通过@Conditional注解来实现条件化配置bean package com.sl.ioc; import ...

  7. Spring温故而知新 - bean的装配

    Spring装配机制 Spring提供了三种主要的装配机制: 1:通过XML进行显示配置 2:通过Java代码显示配置 3:自动化装配 自动化装配 Spring中IOC容器分两个步骤来完成自动化装配: ...

  8. Spring -bean的装配和注解的使用

    一,bean的装配 bean是依赖注入的,通过spring容器取对象的. 装配方法有: 前面两种没什么好讲的,就改改参数就好了. 这里重要讲注解. 注解的主要类型见图,其中component是bean ...

  9. bean的装配方式(注入方式,构造注入,setter属性注入)

    bean的装配方式有两种,构造注入和setter属性注入. public class User { private String username; private String password; ...

  10. Spring XML配置里的Bean自动装配

    Spring自动装配 这段是我们之前编写的代码,代码中我们使用了P命名空间 并且使用手动装配的方式将car <bean id="address" class="cn ...

随机推荐

  1. Centos 7 配置单机Hadoop

    Centos 7 配置单机Hadoop 2018年10月11日 09:48:13 GT_Stone 阅读数:82   系统镜像:CentuOS-7-x86_64-Everything-1708 Jav ...

  2. Bootstrap源码解读之栅格化篇

    本文纯属自己研究所写笔记,如果有错误还请多多指教提出 版心(container) 版心:class名为.container的容器,其版心的宽度在各个屏幕设备下是不一样的值,版心两边就是留白. 各尺寸下 ...

  3. ElasticSearch优化系列二:机器设置(内存)

    预留一半内存给Lucene使用 一个常见的问题是配置堆太大.你有一个64 GB的机器,觉得JVM内存越大越好,想给Elasticsearch所有64 GB的内存. 当然,内存对于Elasticsear ...

  4. DELPHI DOUBLE不解之迷

    procedure TForm1.cmd2Click(Sender: TObject);var str1, str2: string; LValue1: Double; LValue2: Extend ...

  5. 手动封装一个属于自己的AJAX类库

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. python range,xrange区别

    range: 直接生成一个列表对象 xrange: 生成一个xrange对象 xrange使用: 操作一个非常大的数据时,而且没存比较吃紧的时,可以使用xrange来节省内存 xrange一般在循环里 ...

  7. (数据科学学习手札47)基于Python的网络数据采集实战(2)

    一.简介 马上大四了,最近在暑期实习,在数据挖掘的主业之外,也帮助同事做了很多网络数据采集的内容,接下来的数篇文章就将一一罗列出来,来续写几个月前开的这个网络数据采集实战的坑. 二.马蜂窝评论数据采集 ...

  8. ubuntu配置机器学习环境(二) cuda 和cudnn 安装

    Nvidia CUDA Toolkit的安装(cuda) PS:特别推荐*.deb的方法,目前已提供离线版的deb文件,该方法比较简单,不需要切换到tty模式,因此不再提供原来的*.run安装方法,这 ...

  9. 201552-53 《Java程序设计》第五周问题汇总

    201552-53 <Java程序设计>第五周问题汇总 1.编译时,终端显示: 注:XXX.java使用了未经检查或不安全的操作,如何解决? 解答:并不是错误,可以忽视. 2.构造函数与类 ...

  10. 20155318 《Java程序设计》实验一(Java开发环境的熟悉)实验报告

    20155318 <Java程序设计>实验一(Java开发环境的熟悉)实验报告 一.实验内容及步骤 (一)命令行下Java程序开发 步骤一(新建文件夹): 打开windows下的cmd → ...