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

    输出:

  • 相关阅读:
    KALI LINUX 核心概念讲解,持续更新
    KALI LINUX 工具大全之密码破解 --- BruteSpray ( 暴力喷雾 )
    android studio的 gradle 依赖同步错误解决方法
    安卓逆向的初步研究--从某恋app入手
    nc浏览器的十宗罪
    手机重要文件目录(换新机可能要用到)
    国产手机的谷X服务
    安卓手机设置的那些琐事
    办公中遇见的那些问题
    装系统遇到的那些问题
  • 原文地址:https://www.cnblogs.com/-beauTiFul/p/6347167.html
Copyright © 2011-2022 走看看