XML配置AOP
package com.zchen.aop;import org.aspectj.lang.ProceedingJoinPoint;import org.aspectj.lang.annotation.Around;import org.aspectj.lang.annotation.Aspect;import org.aspectj.lang.annotation.Before;import org.aspectj.lang.annotation.Pointcut;public class LogInterceptor {public void myMethod(){};public void before() {System.out.println("method before");}public void aroundMethod(ProceedingJoinPoint pjp) throws Throwable {System.out.println("method around start");pjp.proceed();System.out.println("method around end");}}
?
<?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:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"><context:annotation-config /><context:component-scan base-package="com.zchen"/><bean id="logInterceptor" ref="logInterceptor"><aop:before method="before" pointcut="execution(public * com.zchen.service..*.add(..))" /></aop:aspect></aop:config></beans>
?