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("=================");
        }
    }

    输出:

  • 相关阅读:
    管理信息系统的开发与管理
    加载静态文件,父模板的继承和扩展(2017.11.3)
    开始Flask项目(2017.11.3)
    夜间模式的开启与关闭,父模板的制作(2017.11.2)
    完成登录与注册页面的前端(2017.10.31)
    JavaScript 基础,登录验证(2017.10.24)
    CSS实例:图片导航块(2017.10.20)
    导航,头部,CSS基础 (10.18)
    ASCII表
    RSA加密算法
  • 原文地址:https://www.cnblogs.com/-beauTiFul/p/6347167.html
Copyright © 2011-2022 走看看