标签:work 引用 execution utf-8 png 除了 err path 多重
3、声明切入点
示例:
<?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" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd"> <context:component-scan base-package="com.atguigu.spring.aopxml"></context:component-scan> <aop:config> <aop:aspect ref="myLogger"> <!-- <aop:before method="before" pointcut="execution(* com.atguigu.spring.aopxml.*.*(..))"/> --> <aop:pointcut expression="execution(* com.atguigu.spring.aopxml.*.*(..))" id="cut"/> <aop:before method="before" pointcut-ref="cut"/> </aop:aspect> </aop:config> </beans>
package com.atguigu.spring.aopxml; import org.springframework.stereotype.Component; @Component public class MyLogger { public void before() { System.out.println("前置通知"); } }
package com.atguigu.spring.aopxml; import org.springframework.stereotype.Component; @Component public class MathImpl implements MathI { @Override public int add(int i, int j) { int result = i + j; return result; } @Override public int sub(int i, int j) { int result = i - j; return result; } @Override public int mul(int i, int j) { int result = i * j; return result; } @Override public int div(int i, int j) { int result = i / j; return result; } }
package com.atguigu.spring.aopxml; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class Test { public static void main(String[] args) { ApplicationContext ac = new ClassPathXmlApplicationContext("aop-xml.xml"); MathI math = ac.getBean("mathImpl", MathI.class); int add = math.add(12, 12); System.out.println(add); } }
标签:work 引用 execution utf-8 png 除了 err path 多重
原文地址:https://www.cnblogs.com/lemonzhang/p/12910941.html