在eclipse中使用Aspectj
2016-07-01 20:54
281 查看
Aspectj是一种面向切面的框架,用它可以实现面向切面编程。在eclipse如果要使用Aspectj需要安装ADJT插件,安装方法如下
1. 下载安装包,下载地址
在eclipse中安装
选择【Archive】->选择刚刚下载好的压缩包" title="">
之后稍等片刻,喝点水….
3. 写一个小Demo
首先写一个普通的类Login
再写一个用aspect打开的文件Test(我也不懂这样说对不对,可以用这样的方法创建它)
之后测试一下
可以看到运行userLogin方法之前和之后自动加上了Test类中的代码
1. 下载安装包,下载地址
在eclipse中安装
选择【Archive】->选择刚刚下载好的压缩包" title="">
之后稍等片刻,喝点水….
3. 写一个小Demo
首先写一个普通的类Login
package com.service; import org.springframework.stereotype.Component; @Component public class Login { public void userLogin(String name) { System.out.println(name+"用户登录"); } }
再写一个用aspect打开的文件Test(我也不懂这样说对不对,可以用这样的方法创建它)
package com.aspect; public aspect Test { /** * 此处的ececution中的参数中的com.service.Login是指运行 * com.service.Login类运行前 * 第一个*号是指返回值不限,第二个*号是指方法名不限 * 括号只是任意个数类型不限的形参 */ before() : execution(* com.service.Login.*(..)) { System.out.println("登录前的检查"); } after() : execution(* com.service.Login.*(..)) { System.out.println("登录后的检查"); } }
之后测试一下
@Test public void testAspectJ() { ApplicationContext applicationContext = new ClassPathXmlApplicationContext("beans.xml"); Login login = applicationContext.getBean("login", Login.class); login.userLogin("Slence"); }
可以看到运行userLogin方法之前和之后自动加上了Test类中的代码
相关文章推荐
- 使用Aspect来对访问方法进行预处理和后处理
- [转]ASP.NET MVC Dynamic Themes
- AnnotationAwareAspectJAutoProxyCreator is only available on Java 1.5 and higher
- aspx文件的构成
- 七天学会ASP.NET MVC (五)——Layout页面使用和用户角色管理
- 构建高性能ASP.NET站点 第五章—性能调优综述(后篇)
- 构建高性能ASP.NET站点 第五章—性能调优综述(中篇)
- ASP.NET MVC 教程学习
- 构建高性能ASP.NET站点之一 剖析页面的处理过程(前端)
- 2014年基于Raspberry Pi的5大项目
- 2014年基于Raspberry Pi的5大项目
- 聊聊asp.net中Web Api的使用
- asp.net之Repeater ItemTemplate 图片上传 + 立即显示
- ASP.NET多个Button的页面,回车执行按钮事件(转)
- ReportViewer 類別
- 在asp.net WebAPI 中 使用Forms认证和ModelValidata(模型验证)
- ASP 连接Access数据库的登陆系统
- ASP.NET Razor - C# Variables
- ASP.NET中IsPostBack详解
- ASP.NET Razor - C# and VB Code Syntax