博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring Aop基础总结
阅读量:4630 次
发布时间:2019-06-09

本文共 1343 字,大约阅读时间需要 4 分钟。

什么是AOP:

       Aop技术是Spring核心特性之中的一个,定义一个切面。切面上包括一些附加的业务逻辑代码。在程序运行的过程中找到一个切点,把切面放置在此处,程序运行到此处时候会运行切面上的代码。这就是AOP.。

AOP的实现机制是什么:

       Aop是基于动态代理模式实现的,被代理类实现过接口,能够用反射包里的InvocationHandler和Proxy实现。被代理类没有实现过接口。能够用cglib生成二进制码获得代理类。

AOP有什么用途:

        Aop用处许多,比方在程序中加入事物,加入日志等。

AOP怎样使用:

       能够通过注解的方式和xml配置的方式使用Aop,例如以下是配置的Aop.

 使用AOP。在UserDao的save方法前后,切入程序:

          

UserDao          

package com.dao;public class UserDao {	public void save(){		System.out.println("in save");	}}

切面程序,在save方法运行前后要运行的程序:

package com.aop;import org.aspectj.lang.ProceedingJoinPoint;public class ServiceAop {	public void before(){		System.out.println("in before");	}	public void after(){		System.out.println("in after");	}	public void around(ProceedingJoinPoint pjp) throws Throwable{		System.out.println("around in before");		pjp.proceed();		System.out.println("around in after");	}}

 applicationContext.xml

測试类:

package com.dao;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;public class Test {	public static void main(String[] args) {		ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");		UserDao ud=(UserDao) ac.getBean("userDao");		ud.save();	}}

转载于:https://www.cnblogs.com/yangykaifa/p/7294111.html

你可能感兴趣的文章
Cocos2d-x学习笔记(三十)之 游戏存档
查看>>
对相机所看的视角截屏保存为图片
查看>>
最快地复制一张表
查看>>
Asp.Net 构架(HttpModule 介绍)
查看>>
PHP-错误处理
查看>>
[C#][EF] 添加表添加不进来
查看>>
jquery radio 取值
查看>>
WebFrom模拟MVC
查看>>
【转】Mac 程序员的十种武器
查看>>
Install Package and Software
查看>>
沙漏图分析
查看>>
spark-submit --files 动态加载外部资源文件
查看>>
人机猜拳(这是最近的一个总结)
查看>>
python函数
查看>>
模板引擎:Velocity&FreeMarker(转)
查看>>
Anaconda安装,jupyter notebook 使用说明
查看>>
别人总结的批处理技巧
查看>>
sql server 2014预览版发布
查看>>
正则表达式string对象方法
查看>>
解析json实例
查看>>