import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.aspectj.lang.JoinPoint; @Aspect public class LoggingAspect { @Before("execution(* com.example.MyClass.myMethod(..))") public void logBefore(JoinPoint joinPoint) { System.out.println("Before " + joinPoint.getSignature().getName() + " method"); } } <beans xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <aop:aspectj-autoproxy /> <bean id="loggingAspect" class="com.example.LoggingAspect" /> <aop:config> <aop:aspect ref="loggingAspect"> <aop:pointcut id="myPointcut" expression="execution(* com.example.MyClass.myMethod(..))" /> <aop:before pointcut-ref="myPointcut" method="logBefore" /> </aop:aspect> </aop:config>


上一篇:
下一篇:
切换中文