spring总结

1.功能:
IOC 控制反转(Inversion of Control)
所谓控制反转就是应用本身不负责依赖对象的创建及维护,依赖对象的创建及维护是由外部容器负责的。
DI 依赖注入(Dependency Injection)
所谓依赖注入就是指:在运行期,由外部容器动态地将依赖对象注入到组件中。
2.配置(IOC、DI):

  • org.springframework.beans-3.2.0.RELEASE.jar
  • org.springframework.context-3.2.0.RELEASE.jar
  • org.springframework.core-3.2.0.RELEASE.jar
  • org.springframework.expression-3.2.0.RELEASE.jar
  • org.apache.commons.logging-1.1.1.jar
    3.创建spring的配置模板
<?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“>

4.实例化spring
ApplicationContext ctx = new ClassPathXmlApplicationContext(“applicationContext.xml”);
5.bean配置
【1】简单bean配置





【2】引用其它bean(外部bean)





【3】引用其它bean(内部bean)






【4】使用p命名空间
xmlns:p=“http://www.springframework.org/schema/p
http://www.springframework.org/schema/p
http://www.springframework.org/schema/p/spring-p.xsd
【5】装配集合List和数组

list1 list2 obj1 obj2 【6】装配set set1 set2 set使用方法和list一样,不同的是对象被装配到set中,而list是装配到List或数组中装配。 【7】装配map: map01 map02 简化为: map中的的数值和以及的一样,可以使任何有效的属性元素,需要注意的是key值必须是String的。 【8】装配集合Property prop1 prop2 【9】装配集合List(null) 6.注解: @Autowired或@Resource注解 【1】引入context命名空间 需要在xml配置文件中配置以下信息: 【2】在配置文件中添加context:annotation-config标签 【3】使用注解@autowired标注在属性上 @Qualifier(“personDao”)该注解以名字为条件查找依赖对象 【4】使用注解@Resource标注在属性上 【5】使用@Value注解装配值
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值