一、依赖注入的三种注入方式

  Spring框架为我们提供了三种注入方式:set注入、构造方法注入和接口注入。

  1、set注入

    规律:无论给什么赋值,配置文件中<property>标签的name属性值一定和对象中的名称一致。

    1)普通字符类型注入

 <bean id="" class="">
<property name="" value=""/>
</bean>

    

    2)对象注入

 <bean id="" class="">
<property name="" ref=""/>
</bean>

    3)list集合注入

 <bean id="" class="">
<property name="">
<list>
<value></value>
<value></value>
<value></value>
</list>
</property>   
</bean>

    4)属性文件中的字段的注入

 <bean id="" class="">
<property name="props">
<props key=""></props>
<props key=""></props>
<props key=""></props>
</property>
</bean> 注意:props是类中的资源文件类的对象

     

  2、构造方法注入

    1)一个参数

    

 <bean id="" class="">
<constructor-args value=""/>
</bean>

    2)两个参数

      当参数为非字符串类型时,在配置文件中需要制定类型,如果不指定类型一律按照字符串类型赋值。

      当参数类型不一致时,框架是按照字符串的类型进行查找的,因此需要在配置文件中制定是参数的位置。

    

 <constructor-arg value="admin" index="0"/>
<constructor-arg value="23" type="int" index="1"/>

Spring框架学习(二)的更多相关文章

  1. spring框架学习(二)——注解方式IOC/DI

    什么是注解 传统的Spring做法是使用.xml文件来对bean进行注入或者是配置aop.事物,这么做有两个缺点: 1.如果所有的内容都配置在.xml文件中,那么.xml文件将会十分庞大:如果按需求分 ...

  2. Spring框架学习总结(上)

    目录 1.Spring的概述 2.Spring的入门(IOC) 3.Spring的工厂类 4.Spring的配置 5.Spring的属性注入 6.Spring的分模块开发的配置 @ 1.Spring的 ...

  3. Spring框架学习之IOC(二)

    Spring框架学习之IOC(二) 接着上一篇的内容,下面开始IOC基于注解装配相关的内容 在 classpath 中扫描组件 <context:component-scan> 特定组件包 ...

  4. Spring框架学习一

    Spring框架学习,转自http://blog.csdn.net/lishuangzhe7047/article/details/20740209 Spring框架学习(一) 1.什么是Spring ...

  5. Spring框架学习1

    AnonymouL 兴之所至,心之所安;尽其在我,顺其自然 新随笔 管理   Spring框架学习(一)   阅读目录 一. spring概述 核心容器: Spring 上下文: Spring AOP ...

  6. Spring框架学习笔记(1)

    Spring 框架学习笔记(1) 一.简介 Rod Johnson(spring之父) Spring是分层的Java SE/EE应用 full-stack(服务端的全栈)轻量级(跟EJB比)开源框架, ...

  7. Struts2框架学习(二) Action

    Struts2框架学习(二) Action Struts2框架中的Action类是一个单独的javabean对象.不像Struts1中还要去继承HttpServlet,耦合度减小了. 1,流程 拦截器 ...

  8. spring框架学习(三)junit单元测试

    spring框架学习(三)junit单元测试 单元测试不是头一次听说了,但只是听说从来没有用过.一个模块怎么测试呢,是不是得专门为一单元写一个测试程序,然后将测试单元代码拿过来测试? 我是这么想的.学 ...

  9. spring 框架学习网站

    spring 框架学习网站 NO1 http://www.mkyong.com NO2 https://spring.io/docs/reference

随机推荐

  1. js相关总结

    1.都是gbk格式的页面使用ajax请求,发起前改变编码格式,可避免乱码. $.ajaxSetup({     'beforeSend' : function(xhr) {         xhr.o ...

  2. treegrid and datagrid ctrl or shift selectRow

    var tg = $('#tg');tg.treegrid({...}); // create treegridvar panel = tg.treegrid('getPanel');var body ...

  3. [问题2014S02] 复旦高等代数II(13级)每周一题(第二教学周)

    问题2014S02  设实系数多项式 \begin{eqnarray*}f(x) &=& a_nx^n+a_{n-1}x^{n-1}+\cdots+a_1x+a_0, \\ g(x) ...

  4. Java动态代理的两种实现方式:

    方式一:传统的代理 package cn.hc.domain; import java.lang.reflect.InvocationHandler; import java.lang.reflect ...

  5. Creating Custom Login Screen In Oracle Forms 10g

    Below is the example plsql unit to validate login credentials and after successful validation open a ...

  6. iOS开发数据库篇—SQLite的应用

    iOS开发数据库篇—SQLite的应用 一.简单说明 在iOS中使用SQLite3,首先要添加库文件libsqlite3.dylib和导入主头文件. 导入头文件,可以使用库中的函数(是纯C语言的) 二 ...

  7. js模板引擎

    js模板引擎包括如下: template 官方参考:http://aui.github.io/artTemplate BaiduTemplate 官方参考:http://baidufe.github. ...

  8. UiAutomator环境搭建及详细操作

    一.环境搭建 1.1 必备条件 JDK SDK(API高于15) Eclipse(安装ADT插件) ANT(用于编译生成的jar) 安装JDK并添加环境变量 1.2 详细步骤 1.安装JDK并添加环境 ...

  9. 【转】Hostapd工作流程分析

    [转]Hostapd工作流程分析 转自:http://blog.chinaunix.net/uid-30081165-id-5290531.html Hostapd是一个运行在用户态的守护进程,可以通 ...

  10. 用单分子测序(single-molecule sequencing)和局部敏感哈希(locality-sensitive hashing)来组装大型基因组

    Assembling large genomes with single-molecule sequencing and locality-sensitive hashing 好好读读,算法系列的好文 ...