package com.mangocity.spring.test; /** * 切面类 * @author test * */ public class Spring3_1Test { public void beforePrintContent(String name) { System.out.println("beforePrintContent..."+name); } public void afterPrintContent() { System.out.println("afterPrintContent..."); } } package com.mangocity.spring.test; /** * 目标类 * @author test * */ public class Spring { public void argsTest(String name) { System.out.println(name); } } spring配置 <?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"> <!-- 实例化 --> <bean id="salService" class="com.mangocity.spring.test.Spring"/> <bean id="implement" class="com.mangocity.spring.test.Spring3_1Test"/> <aop:config> <!-- 切入点 有参数 --> <aop:pointcut id="pointcut" expression="execution(* com.mangocity..*.*.*(..)) and args(arg1)"/> <aop:aspect ref="implement"> <!-- 有参数传值 arg-names的名字需与args中的参数名一致 --> <aop:before pointcut-ref="pointcut" method="beforePrintContent" arg-names="arg1"/> <!-- 无参数 --> <aop:after pointcut="execution(* com.mangocity..*.*.*(..))" method="afterPrintContent"/> </aop:aspect> </aop:config> </beans> 测试类: package com.mangocity.spring.test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class SpringTest { public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); Spring s = (Spring) context.getBean("salService"); s.argsTest("测试"); } } 输出结果: beforePrintContent...测试 测试 afterPrintContent...
相关推荐
spring AOP的实例代码,有着详细的讲解,
SpringAop实例,包括xml和配置两种方式.jar齐全
使用SpringAOP完成日志记录功能的实例
基于xml代码的SpringAOP实例详解,适合初步学习springAOP的开发人员了解该功能的使用。
spring aop
Spring AOP 实例源码!!!!!!!!!!!!!!!!!!!!!!!!
一个基于@AspectJ的spring2.0 AOP应用实例,很小很简单,没有任何额外信息,最适合AOP入门学习。使用log4j打印信息。把项目直接import进myeclipse就可以使用啦......
Spring Aop实例(AOP 如此简单)@Aspect、@Around 注解方式配置
spring AOP 实例 调试通过的 很精简的代码,只有AOP相关的几个类,不牵涉任何杂七杂八的东西,用于AOP学习很好。
NULL 博文链接:https://306963591.iteye.com/blog/1129837
1、spring切入点 2、spring前置织入,传入参数处理 3、spring后置织入,传入参数处理 4、环绕织入,参数及返回值处理 5、返回后织入,返回值处理 6、异常织入,异常处理 maven环境下,测试用例可直接运行
NULL 博文链接:https://bijian1013.iteye.com/blog/2142528
Spring AOP 几个不同使用方法的完整例子,使用Junit4c测试, 在我的博客上有不同配置组合的说明,可以参考
spring aop部分的简单实例,容易理解
1.简单的AOP日志实现-某方法之前的前后记录日志; 2.简单的AOP日志实现-需要记录方法的运行时间; 3.简单的AOP日志实现-增加检查订单功能;
spring aop 经典例子(原创),无论新手还是老手,可以快速对Spring AOP有个总体的认识。基于JDK1.6,Spring2.0.5,Eclipse IDE。
spring 采用aop 的实例
Spring Aop的使用实例