/**
* @author zhuc
* @version 2012-8-21 下午1:38:39
*/
@Aspect
@Component
public class Aspect2 {
/**
* @param joinPoint
* @param log
*/
@After(value = "@annotation(log)")
public void doAfter(JoinPoint joinPoint, Log log) {
for (Object obj : joinPoint.getArgs()) {
System.out.println("参数: " + obj);
}
System.out.println(log.function() + "," + log.desc());
System.out.println("doAfter......");
}
}
/**
* @author zhuc
* @version 2012-8-21 下午1:42:07
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Log {
String function() default "";
String desc() default "";
}
/**
* @author zhuc
*
*/
public class Service {
/**
* @param name
* @return
*/
@Log(function = "日志管理", desc = "添加Log")
public String addLog(String name) {
System.out.println(name);
return "hello:" + name;
}
}
<?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"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<context:component-scan base-package="org.zhuc.maven.aspectj" />
<aop:aspectj-autoproxy />
<bean id="service" class="org.zhuc.maven.aspectj.Service" />
</beans>
/**
* @author zhuc
* @version 2012-8-21 下午1:45:19
*/
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
ApplicationContext ac = new FileSystemXmlApplicationContext(
"src/test/java/org/zhuc/maven/aspectj/aspectj.xml");
Service s = (Service) ac.getBean("service");
String str = s.addLog("zhuc");
System.out.println(str);
}
}
运行结果:
zhuc
参数: zhuc
日志管理,添加Log
doAfter......
hello:zhuc
分享到:
相关推荐
spring aspectj aspectrt.jar
spring通过aspectj来实现事务控制
Spring 使用AspectJ 实现 AOP之前置通知小例子,实际跑过,验证可信。
NULL 博文链接:https://fei-xiang.iteye.com/blog/521637
Spring4.3.7的AOP依赖包-AspectJ
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
aspectj.jar的1.9.0版本,下载后粘贴到所属的lib文件下即可
NULL 博文链接:https://rain1109.iteye.com/blog/1838100
主要对Spring AOP的相关概念和简单的静态代理、动态代理以及常见的几种AOP配置方式做总结学习。主要包括:1. AOP的常见概念 2. 静态代理 3. jdk动态代理 4. Aspectj and Aspectjweaver 5. **aop-config** 6. CGLIB ...
Spring AOP之基于AspectJ注解总结与案例 ,具体效果和过程看博文 http://blog.csdn.net/evankaka/article/details/45394409
Spring 使用AspectJ 实现 AOP(基于xml文件、基于注解)
spring和aspectj的aop实验,详细内容可以移步至博客:https://mp.csdn.net/postedit/97750888
NULL 博文链接:https://hbiao68.iteye.com/blog/1487107
aspectj
AspectJ shows its real power when combined with Spring. This new edition focuses on Spring-AspectJ integration, which is a major feature of Spring 2.5. Readers will find this edition immensely helpful...
aspectj的jar spring使用aop需要的jar 使用aop
要在 Spring 应用中使用 AspectJ 注解, 必须在 classpath 下包含 AspectJ 类库: aopalliance.jar、aspectj.weaver.jar 和 spring-aspects.jar等jar包,文件已打包上传。
Spring spectJ AOP 前置通知 后置通知 返回通知 异常通知 环绕通知
Spring4 In Action-4.2-@AspectJ-切面,Spring4 In Action-4.2-@AspectJ-切面。Spring4 In Action-4.2-@AspectJ-切面
一个基于@AspectJ的spring2.0 AOP应用实例,很小很简单,没有任何额外信息,最适合AOP入门学习。使用log4j打印信息。把项目直接import进myeclipse就可以使用啦......