今天记录一下学习aspectj的一点代码
在做aspectj的代码需要引入的jar
aspectj/
aspectjlib.jar
aspectrt.jar
aspectjtools.jar
aspectweaver.jar
cglib/
cglib-2.2.2.jar
asm.jar
spring-aspectj/
spring-aspects.jar
配置文件 aop.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<aop:aspectj-autoproxy />
<bean id="aspect" class="com.jimmy.aop.AspectHello" />
<bean id="hello" class="com.jimmy.aop.Hello" />
</beans>
代码
AspectHello.java
package com.jimmy.aop;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
@Aspect
public class AspectHello {
@After("execution(* com.jimmy.aop.Hello.say(..))&& args(words)")
public void aa(String words) {
System.out.println(words+" kkkk");
}
@Before("execution(* com.jimmy.aop.Hello.say(..)) && args(words, a)")
public void aa(String words, int a) {
System.out.println(a+" "+words+" kkkk");
}
}
Hello.java
package com.jimmy.aop;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Hello {
public void say(String words){
System.out.println("hello "+words);
}
public void say(String words, int a){
System.out.println(a + " hello "+words);
}
public static void main(String[] args){
ApplicationContext context=
new ClassPathXmlApplicationContext(new String[]{"aop.xml"});
Hello hello=(Hello)context.getBean("hello");
hello.say("jimmy");
hello.say("jimmy", 1);
}
}
运行结果:
hello jimmy
jimmy kkkk
1 jimmy kkkk
1 hello jimmy
分享到:
相关推荐
Spring AOP的AspectJ支持jar包; 包括: com.springsource.net.sf.cglib-2.2.0.jar com.srpingsource.org.aopalliance-1.0.0.jar com.srpingsource.org.aspectj.weaver-1.68.RELEASE.jar
包含学习Spring AOP以及学习Spring Aspect J需要新增的jar包,需要的朋友可以下载哦!
主要对Spring AOP的相关概念和简单的静态代理、动态代理以及常见的几种AOP配置方式做总结学习。主要包括:1. AOP的常见概念 2. 静态代理 3. jdk动态代理 4. Aspectj and Aspectjweaver 5. **aop-config** 6. CGLIB ...
aspectj的jar spring使用aop需要的jar 使用aop
Spring 使用AspectJ 实现 AOP(基于xml文件、基于注解)
主要介绍了Spring AOP AspectJ使用及配置过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
以公司订单管理的模型为例(大部分步骤和业务了逻辑已经删除,只保存AOP注解这一部分)Spring AOP
spring aop jar 包
一个基于@AspectJ的spring2.0 AOP应用实例,很小很简单,没有任何额外信息,最适合AOP入门学习。使用log4j打印信息。把项目直接import进myeclipse就可以使用啦......
描述一下Spring AOP? 在Spring AOP中关注点(concern)和横切关注点(cross-cutting concern)有什么不同? AOP有哪些可用的实现? Spring中有哪些不同的通知类型(advice types)? Spring AOP 代理是什么? 引介...
spring aop spring aop spring aop spring aop spring aop spring aop spring aop spring aop spring aop
Spring 使用AspectJ 实现 AOP之前置通知小例子,实际跑过,验证可信。
spring-aop-1.1.1.jar spring-aop-1.2.6.jar spring-aop-1.2.9.jar spring-aop-2.0.2.jar spring-aop-2.0.6.jar spring-aop-2.0.7.jar spring-aop-2.0.8.jar spring-aop-2.0.jar spring-aop-2.5.1.jar spring-aop-...
一、适合人群 1、具备一定Java编程基础,初级开发者 2、对springboot,mybatis,mysql有基本认识 3、对spring aop认识模糊的,不清楚如何实现Java 自定义注解的 ...4、spring boot,mybatis,druid,spring aop的使用
Spring AOP之基于AspectJ注解总结与案例 ,具体效果和过程看博文 http://blog.csdn.net/evankaka/article/details/45394409
@AspectJ配置Spring AOP,文档,Aspect jar包, 可运行的demo,
下面小编就为大家分享一篇Spring Aop之AspectJ注解配置实现日志管理的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
基于注解实现SpringAop基于注解实现SpringAop基于注解实现SpringAop
NULL 博文链接:https://quicker.iteye.com/blog/670885
死磕Spring之AOP篇 - Spring AOP两种代理对象的拦截处理(csdn)————程序