zoukankan      html  css  js  c++  java
  • AOP:Spring的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">
        
        <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("=================");
        }
    }

    输出:

  • 相关阅读:
    c# 暴力破解中文编码方式
    vs调试 不能进入断点
    shell-的bash内部命令变量介绍与shift等
    shell-的特殊变量-难点理论
    shell-的特殊变量-进程状态变量$$ $! $? $_详解
    shell-的特殊变量-位置变量$0 $n $* $# $@详解
    shell-的变量-局部变量
    shell-的变量-全局变量
    shell-脚本开发基本规范及习惯
    shell-脚本的执行
  • 原文地址:https://www.cnblogs.com/-beauTiFul/p/6347167.html
Copyright © 2011-2022 走看看