关于网站建设的大学,做一个网站 如何盈利,重庆市交易中心招标网,wordpress统计和谷歌不同基于XML的AOP实现 主要是使用XML去代替注解#xff0c;来实现起到代替注解的作用#xff0c;实际使用频率很低 除了Component注解#xff0c;将里面其他的注解都注释掉
spring-aop-xml.xml
?xml version1.0 encodingUTF-8?
beans x…基于XML的AOP实现 主要是使用XML去代替注解来实现起到代替注解的作用实际使用频率很低 除了Component注解将里面其他的注解都注释掉
spring-aop-xml.xml
?xml version1.0 encodingUTF-8?
beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:contexthttp://www.springframework.org/schema/contextxmlns:aophttp://www.springframework.org/schema/aopxsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd!--扫描组件--context:component-scan base-packagecom.atguigu.spring.proxy/aop:config!--设置一个公共切入点表达式--aop:pointcut idtestPointCut expressionexecution(* com.atguigu.spring.proxy.CalculatorImpl.*(..))/!--将IOC容器中的某个bean设置为切面(扫描出来的bean默认id为首字母小写)并设置优先级--aop:aspect refloggerAspect order1!--这里就是通过XML代替注解的描述将这个bean中的方法进行引用--aop:before methodbeforeAdviceMethod pointcut-reftestPointCut/!--这里前置通知和环绕通知混合在一起用最终顺序会出现一些问题--aop:after-returning methodafterReturningMethod returningresult pointcut-reftestPointCut/aop:after-throwing methodafterThrowingMethod throwingex pointcut-reftestPointCut/aop:around methodaroundMethod pointcut-reftestPointCut//aop:aspect/aop:config
/beansSpringTest.java Testpublic void testAOPByXML(){ApplicationContext ioc new ClassPathXmlApplicationContext(spring-aop-xml.xml);Calculator calculator ioc.getBean(Calculator.class);calculator.div(1,1);}Logger--前置通知方法名div参数[1, 1]
环绕通知--前置通知方法名div参数[1, 1]
方法内部 result 1
环绕通知--返回通知方法名div结果1
环绕通知--后置通知方法名div
Logger--返回通知方法名div结果1