业务接口
package dao; public interface UserDao { public void addUser(); }
接口实现
package dao; public class UserDaoImpl implements UserDao { @Override public void addUser() { // TODO Auto-generated method stub System.out.println("添加用户"); } }
代理类
package aspect; import org.aspectj.lang.annotation.After; import org.aspectj.lang.annotation.AfterReturning; import org.aspectj.lang.annotation.AfterThrowing; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Pointcut; @Aspect public class UserDaoAspect { //类中开发切入点和各种通知 @Pointcut("execution(* dao..*.*(..))") //切入点 签名就是下面的方法名 public void sayHello(){}; @Before("sayHello()") //前置通知 public void startSay(){ System.out.println("Good Morning"); } @AfterReturning("sayHello()") //后置通知 public void endSay(){ System.out.println("bye bye"); } @AfterThrowing("sayHello()") //异常通知 public void doThrows(){ System.out.println("异常通知"); } @After("sayHello()") //后通知 public void doFinally(){ System.out.println("最终执行"); } }
applicationContext.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:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"> <bean id="userDao" class="dao.UserDaoImpl" /> <bean id="aspectj" class="aspect.UserDaoAspect"></bean> <aop:aspectj-autoproxy/> </beans>
测试类
package test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import dao.UserDao; import dao.UserDaoImpl; public class Test { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml"); UserDao dao=(UserDao)context.getBean("userDao"); dao.addUser(); } }
您还没有登录,请您登录后再发表评论
Spring_Annotation_AOP
NULL 博文链接:https://bijian1013.iteye.com/blog/2142528
Spring mvc Aop+annotation实现系统日志记录功能实现的jar包asm-3.3.jar ,aspectjrt.jar , aspectjweaver.jar , cglib-nodep-2.1_3.jar , spring-aop.jar
NULL 博文链接:https://tianhei.iteye.com/blog/978969
spring-aop实践项目,基于annotation方式的面向切面实践小项目
spring-aop-4.0.4.RELEASE.jar com.springsource.net.sf.cglib-2.2.0.jar com.springsource.org.aopalliance-1.0.0.jar com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar spring-aspects-4.1.2.RELEASE.jar ...
NULL 博文链接:https://dyygusi.iteye.com/blog/1995858
NULL 博文链接:https://baobeituping.iteye.com/blog/1201798
NULL 博文链接:https://dolphin-ygj.iteye.com/blog/548314
spring mvc aop <context:annotation-config />
自己动手做的一个spring aop 的小demo,主要是annotation标签的配置联系,比较简单.
aop入门。
在Spring1.2或之前的版本中,实现AOP的传统方式就是通过实现Spring的AOP API来定义Advice,并设置代理对象。Spring根据Adivce加入到业务流程的时机的不同,提供了四种不同的Advice:Before Advice、After Advice、...
SpringAOP的注解配置完成切面的编程,完成execution,annotation两种表达式的实例Ddemo
NULL 博文链接:https://tuoxinquyu.iteye.com/blog/1465187
nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator]: ...
基于Log4j+SpringAOP+Annotation的可注解日志切面组件 使用方式 @Log(logAfter = true, logBefore = true) public returntype methodName(params) 测试类com.liam.aop.aspect.test.AopLogAnnotationTest 测试输出 ...
spring 的aop的详解如:切面,连接点,通知,切入点,目标对象,代理对象及annotation方式的aop实现和xml方式的事务管理等
NULL 博文链接:https://whp0731.iteye.com/blog/356167
相关推荐
Spring_Annotation_AOP
NULL 博文链接:https://bijian1013.iteye.com/blog/2142528
Spring mvc Aop+annotation实现系统日志记录功能实现的jar包asm-3.3.jar ,aspectjrt.jar , aspectjweaver.jar , cglib-nodep-2.1_3.jar , spring-aop.jar
NULL 博文链接:https://tianhei.iteye.com/blog/978969
spring-aop实践项目,基于annotation方式的面向切面实践小项目
spring-aop-4.0.4.RELEASE.jar com.springsource.net.sf.cglib-2.2.0.jar com.springsource.org.aopalliance-1.0.0.jar com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar spring-aspects-4.1.2.RELEASE.jar ...
NULL 博文链接:https://dyygusi.iteye.com/blog/1995858
NULL 博文链接:https://baobeituping.iteye.com/blog/1201798
NULL 博文链接:https://dolphin-ygj.iteye.com/blog/548314
spring mvc aop <context:annotation-config />
自己动手做的一个spring aop 的小demo,主要是annotation标签的配置联系,比较简单.
aop入门。
在Spring1.2或之前的版本中,实现AOP的传统方式就是通过实现Spring的AOP API来定义Advice,并设置代理对象。Spring根据Adivce加入到业务流程的时机的不同,提供了四种不同的Advice:Before Advice、After Advice、...
SpringAOP的注解配置完成切面的编程,完成execution,annotation两种表达式的实例Ddemo
NULL 博文链接:https://tuoxinquyu.iteye.com/blog/1465187
nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator]: ...
基于Log4j+SpringAOP+Annotation的可注解日志切面组件 使用方式 @Log(logAfter = true, logBefore = true) public returntype methodName(params) 测试类com.liam.aop.aspect.test.AopLogAnnotationTest 测试输出 ...
spring 的aop的详解如:切面,连接点,通知,切入点,目标对象,代理对象及annotation方式的aop实现和xml方式的事务管理等
NULL 博文链接:https://whp0731.iteye.com/blog/356167