public class ExampleClass { public void doSomething() { } } <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>5.3.10</version> </dependency> </dependencies> import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; @Aspect public class LoggingAspect { @Before("execution(* com.example.ExampleClass.doSomething())") public void logBefore(JoinPoint joinPoint) { System.out.println("Before method: " + joinPoint.getSignature().getName()); } } <bean id="exampleClass" class="com.example.ExampleClass" /> <bean id="loggingAspect" class="com.example.LoggingAspect" /> <aop:config> <aop:aspect ref="loggingAspect"> <aop:pointcut expression="execution(* com.example.ExampleClass.doSomething())" id="exampleMethod" /> <aop:before method="logBefore" pointcut-ref="exampleMethod" /> </aop:aspect> </aop:config>


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