public interface SampleService { void doSomething(); } public class SampleServiceImpl implements SampleService { @Override public void doSomething() { System.out.println("Doing something..."); } } @Aspect public class LoggingAspect { @Before("execution(* com.example.SampleService.*(..))") public void beforeExecution(JoinPoint joinPoint) { System.out.println("Before method execution: " + joinPoint.getSignature().getName()); } } <bean id="sampleService" class="com.example.SampleServiceImpl" /> <bean id="loggingAspect" class="com.example.LoggingAspect" /> <aop:aspectj-autoproxy /> public class App { public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); SampleService sampleService = context.getBean("sampleService", SampleService.class); sampleService.doSomething(); } } Before method execution: doSomething Doing something...


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