public interface UserService {
String getUsername();
}
public class UserServiceImpl implements UserService {
@Override
public String getUsername() {
return "John Doe";
}
}
@Aspect
public class LoggingAspect {
@Before("execution(* com.example.UserService.getUsername())")
public void logBefore(JoinPoint joinPoint) {
System.out.println("Before method: " + joinPoint.getSignature().getName());
}
}
@Configuration
public class AopConfig {
@Bean
public UserService userService() {
return MatrixAopProxyFactory.createProxy(new UserServiceImpl());
}
@Bean
public LoggingAspect loggingAspect() {
return new LoggingAspect();
}
}