AOP
1.Spring理解
:管理我们项目业务中的各项Bean(service,dao,Action)实例化类。
DI (Dependency(依赖) Injection(注射器)) 依赖注入
IOC (Inverse of Control) 控制反转 :将组件对象(业务对象)的控制权从 代码本身 转移到 外部容器(Spring容器)
2.AOP(Aspact Oriented Programming)面向切面编程
3.AOP实现日志记录,在添加用户模块之前和之后,加入自己的代码。前置增强接口 MethodBeforeAdvice
后置增强接口 AfterReturningAdvice
4.Spring体系结构四个核心组件
beans:Bean是包装我们应用程序自定义对象Object的,Object中存有数据
core :Context在发现、建立、维护Bean之间关系所需要的一些工具,如资源的加载,资源的抽象等。
context Context就是一个Bean关系的集合
expression
5.控制反转的理解
A.控制反转是一个重要的面向对象的编程法则来削减计算机程序的耦合性问题,也是轻量级的spring框架核心,beans。
B.Ioc控制反转 说的是创建对象实例的控制权剥离Ioc'容器(Spring容器)控制,实际就是xml控制。
6.单例
怎么才能 保证单例的实现:
(1):构造私有
(2):静态私有对象
(3):公有静态方法
jsp和servlet都是单例多线程
单例:singleton
多例:multition
多例模式或多例类有如下的特点:
(1)多例类可有多个实例
(2)多例类必须自己创建、管理自己的实例,并向外界提供自己的实例。
配置 大配置里面的APO
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" 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 http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd "> <bean id="happyService" class="cn.happy.Service.HappyService"></bean>
!-- 增强配置 advice 通知配置 --> <!--前置--> <bean id="LoggerBefore" class="cn.happy.aop.LoggerBefore"></bean> <!--后置--> <bean id="afterAdvice" class="cn.happy.aop.LoggerAfter"></bean>
<!-- aop配置--> <aop:config> <!-- <!– 切点 expression切点表达式–> <aop:pointcut id="pointcut" expression="execution(* *..Service.*.*(..))"></aop:pointcut> --> <!--01.切点--> <aop:pointcut id="pointcut" expression="execution(public void save2(cn.happy.aop.User))"></aop:pointcut> <!--advisor顾问 对他做什么增强 --> <aop:advisor advice-ref="LoggerBefore" pointcut-ref="pointcut"/> <!--<aop:advisor advice-ref="afterAdvice" pointcut-ref="pointcut"/>--> </aop:config>
Aop(面向切面编程)
1.Aop的目标(作用):让我们可以“专心做事”日志记录,事务处理,异常捕获,缓存操作。
2.Aop原理:将复杂的需求解析出来。将散布在系统中的公共功能集中解决。
3.切面:通知和切点的集合4前置增强接口:MethodBefterAdoice
后置 增强接口:AfterReturningAdvice
4.切点 :
如果通知定义了“什么”和“何时”那么切点就定义了“何处”,切点会配通知所要的一个或多个连接点
通知:增强类中的方法
AOP导入的依赖:
<dependency>
<groupId> org.aspectj</groupId >
<artifactId> aspectjweaver</artifactId >
<version> 1.8.7</version>
</dependency>