spring框架总结

Spring思想:

  1. Ioc
  2. di
  3. aop

 

一、创建spring容器

a.从类路径下加载配置文件:

new ClassPathXmlApplicationContext(“classpath:applicationContext.xml”)

b.从硬盘绝对路径下加载配置文件:

FileSystemXmlApplicationContext("d:/xxx/yyy/xxx")

创建对象的方式:

         空参构造:

         <bean id=”” class=””scope=””></bean>

二、Spring属性注入:

1.set注入:

<bean id=””class=””>

         <property name=”” value=””></property>

<property name=”” value=””></property>

<property name=”” value=””></property>

     </bean>

2.构造函数注入:

<bean id=””class=””>

<constructor  name=”” index=””type=””value=””></property>

< constructor  name=”” ref=””></property>

</bean>

 

3.复杂类型注入:

数组

List

Map

Properties

 

三、web.xml配置spring容器

<!-- spring容器 -->

  <context-param>

<param-name>contextConfigLocation</param-name> <param-value>

classpath:spring/applicationContext-*.xml

</param-value>

  </context-param>

  <listener>

<listener-class>

org.springframework.web.context.ContextLoaderListener</listener-class>

  </listener>

四、使用注解配置spring

<!-- 配置扫描器,接口和实现类都在这个路径(包括子孙包目录)下 -->

   <context:component-scan base-package="cn.e3mall.service">

</context:component-scan>

将对象注册到容器

         @Component

         @Service//service层

         @Controller//web层

         @Repository//dao层

修改对象的作用范围

         @Scope(scopeName=”prototype”)

值类型的注入

         @Value (“tom”)

         Private String name;

引用类型的注入

         @Autowired//自动装配

         如果匹配多个对象,将会无法判断装配的是哪个对象

         //这时候可以用

@Qualifier(“name”)//告诉装配的对象的名称

@Resource(name=”value”)//手动注入,之地这个名称的对象

五、Spring的AOP思想

  1. Filter解决乱码问题
  2. 管理事务问题
  3. 拦截器问题

六、spring实现AOP的原理:

动态代理(优先):被代理对象必须要实现接口,才能产生代理对象.如果没有接口将不能使用动态代理技术。

Cglib代理(没有借口的代理):第三方代理技术,cglib代理.可以对任何类生成代理.代理的原理是对目标对象进行继承代理. 如果目标对象被final修饰.那么该类无法被cglib代理。

1.AOP的关键名词

Joinpoint(连接点)                目标对象中所有可以增加的方法

Pointcut(切入点)             目标对象,已经增强的方法

Advice(通知)                   增强的代码

Target(目标对象)             被代理的对象

Weaving(织入)                将通知应用到切面的过程

Proxy(代理)                     将通知织入目标对象之后形成代理对象

Aspect(切面)                   切点+通知

2.AOP的实现方式有两种:

      1)xml注解配置

      2)注解配置

 

 

 

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值