AOP:Spring的xml配置方式
2017-01-24 15:06
501 查看
<?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 name="userManager" class="com.wangcf.manager.UserManagerImp"/> <bean name="logManager" class="com.wangcf.manager.aspect.LogManager"/> <aop:config> <aop:aspect id="logMgrAspect" ref="logManager"> <aop:before method="addLogBefore" pointcut="execution(* com.wangcf.manager.*.add*(..))"/> <aop:after method="addLogAfter" pointcut="execution(* com.wangcf.manager.*.add*(..))"/> </aop:aspect> </aop:config> </beans>
//切面类 package com.wangcf.manager.aspect; import org.aspectj.lang.JoinPoint; public class LogManager { public static void addLogBefore(){ System.out.println("添加日志 Before..."); } public void addLogAfter(){ System.out.println("添加日志记录 After..."); } public void addLogAfterReturning(){ System.out.println("添加日志记录 AfterReturning..."); } public void addLogAfterThrowing(){ System.out.println("添加日志记录 AfterThrowing..."); } public void addLogAround(JoinPoint joinPoint){ System.out.println("添加日志记录 AfterAround start..."); System.out.println(joinPoint.getTarget()); System.out.println("添加日志记录 AfterAround end..."); } }
测试类:
package com.wangcf.test; import org.springframework.beans.factory.BeanFactory; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.wangcf.manager.IUserManager; import com.wangcf.po.User; public class TestAction { public static void main(String[] args) { BeanFactory factory=new ClassPathXmlApplicationContext("applicationContext.xml"); IUserManager userManager=(IUserManager) factory.getBean("userManager"); //输出代理 System.out.println(userManager.getClass().getName()); userManager.addUser(); System.out.println("================="); } }
输出:
![](https://images2015.cnblogs.com/blog/900690/201701/900690-20170124150555425-1216513900.png)
相关文章推荐
- 关于SpringAOP的XML方式的配置
- spring aop的使用(注解方式以及基于xml配置方式)
- Spring AOP (三) XML配置方式
- spring aop的使用(注解方式以及基于xml配置方式)
- 使用Spring的配置xml方式实现AOP
- Spring学习一:IOC(控制反转)和AOP(面向切面)的xml配置和注解方式
- 重温Spring之旅6——基于XML配置方式进行AOP开发
- spring中aop以xml配置方式
- Spring Aop实现——Annotation方式(注解式)and Schema-based式(xml配置)
- SpringAOP2种配置方式(xml方式)
- 实例说明Spring实现AOP的2种方式(注解和XML配置)
- spring aop的使用(注解方式以及基于xml配置方式)
- Spring 基于xml配置方式的AOP
- Spring学习-22:Spring的AOP:基于AspectJ的XML配置方式开发
- Spring aop注解方式和xml配置方式
- 采用annotation的方式配置Spring的IOC和AOP/采用XML的方式配置Spring的IOC和AOP
- Spring AOP 通过XML方式配置各种通知
- 配置Spring AOP,XML方式比Annotation方式略好
- Spring中的AOP(七)——基于XML配置文件方式的AOP
- [5] Spring中的AOP操作(使用xml 配置文件的方式)