spring-依赖注入
2017-05-28 17:12
148 查看
1.依赖注入
依赖:指bean对象的创建依赖于容器。bean对象的依赖资源(对象,常量,空,等等)
2.spring的注入—构造器注入
Spring:IOC—控制反转(3)
3.Spring 注入—setter注入
要求被注入的属性必须有set方法。set方法的方法名由set+属性首字母大写。如果属性是boolean类型,没有get方法是is。
(a)常量注入
(b)bean注入
(c)数组注入
(d)Lits注入
(e)Map注入
(f)Set注入
(g)NULL注入
(h)properties注入
(i)p命名空间注入
9d5f
依赖:指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命名空间注入
9d5f
相关文章推荐
- spring 依赖注入深究
- 详解Java Spring各种依赖注入注解的区别
- Spring、Spring依赖注入与编码剖析Spring依赖注入的原理
- Spring 3.0 基于 Annotation 的依赖注入实现一
- Spring依赖注入常用的两种方式
- spring下应用@Resource, @Autowired 和 @Inject注解进行依赖注入的差异
- Spring中依赖注入的四种方式
- Spring的反射机制和依赖注入
- Spring【依赖注入】就是这么简单
- Spring使用Setter依赖注入
- spring学习之---依赖注入
- Spring 依赖注入的理解
- “围城”式困境中的依赖注入模式及Spring(2)
- spring boot项目依赖spring mvc项目注入失败问题
- Spring 依赖注入四种方式
- Spring_使用XML配置文件实现依赖注入
- “围城”式困境中的依赖注入模式及Spring(3)
- Spring源码分析----IOC依赖注入
- day01-spring2.5.5中使用“依赖注入的注解”
- Spring两大依赖注入的注入时间