spring-依赖注入
来源:互联网 发布:路由器端口转发是什么 编辑:程序博客网 时间:2024/05/17 04:59
1.依赖注入
依赖:指bean对象的创建依赖于容器。bean对象的依赖资源(对象,常量,空,等等)
2.spring的注入—构造器注入
Spring:IOC—控制反转(3)
3.Spring 注入—setter注入
要求被注入的属性必须有set方法。set方法的方法名由set+属性首字母大写。如果属性是boolean类型,没有get方法是is。
(a)常量注入
<?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="student" class="com.et.vo.Student"> <property name="name" value="elliott"></property> </bean></beans>
(b)bean注入
<?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="addr" class="com.et.vo.address"/> <bean id="student" class="com.et.vo.Student"> <property name="name" value="elliott"/> <property name="addr" ref="addr"/> </bean></beans>
(c)数组注入
<property name="books"> <array> <value>Java面向对象编程</value> <value>Python基本教程</value> <value>C语言程序设计</value> </array> </property>
(d)Lits注入
<property name="hobbies"> <list> <value>篮球</value> <value>足球</value> <value>羽毛球</value> </list> </property>
(e)Map注入
<property name="cards"> <map> <entry key="中国银行" value="111111"/> <entry> <key><value>建设银行</value></key> <value>222222</value> </entry> </map> </property>
(f)Set注入
<property name="games"> <set> <value>英雄联盟</value> <value>阴阳师</value> </set> </property>
(g)NULL注入
<property name="wife"> <null/> </property>
(h)properties注入
<property name="info"> <props> <prop key="学号">2017000001></prop> <prop key="sex">男</prop> <prop key="name">Elliott</prop> </props> </property>
(i)p命名空间注入
阅读全文
0 0
- Spring依赖注入:注解注入
- spring 的依赖注入
- Spring依赖注入实践经验
- Spring的依赖注入
- Spring依赖注入
- spring(依赖注入-DI)
- spring依赖注入
- spring依赖注入
- 白话spring依赖注入
- Spring依赖注入方式
- Spring的依赖注入
- Spring依赖注入
- Spring依赖注入方式
- Spring 依赖注入
- spring依赖注入方式
- spring的依赖注入
- Spring依赖注入方式
- Spring依赖注入方式:
- 一些链表问题
- BP神经网络的预测模型
- 深入理解javascript原型和闭包(5)——instanceof
- 运行Linux程序的三种方法
- 数据结构二叉树线索化
- spring-依赖注入
- Can you answer these queries?
- L先生与解密
- mysql查询时,offset过大影响性能的原因与优化方法
- mysql编程之生日问题
- java基础篇(六)——三大特性之继承
- Java安全组成、包及第三方扩展
- 我为什么从SVN转向GIT
- QT编写的数独求解软件、一个数独快速高效的求解算法