Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Component
- public class Test{
- public void reportInPrivateMethod() {
- System.out.println("private method");
- }
- public void reportInPublicMethod() {
- System.out.println("public method");
- }
- }
- @Component
- public class ScheduledTasks {
- @Autowired
- private Test test;
- private static final Logger log = LoggerFactory.getLogger(ScheduledTasks.class);
- private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
- @Scheduled(fixedRate = 5000)
- public void reportCurrentTime() {
- test.reportInPrivateMethod();
- test.reportInPublicMethod();
- log.info("The time is now {}", dateFormat.format(new Date()));
- }
- }
- @Aspect
- @Component
- public class Monitor {
- @Before("execution(* com.zeph.aop.ScheduledTasks.reportCurrentTime())")
- public void logServiceAccess(JoinPoint joinPoint) {
- System.out.println("Completed: " + joinPoint);
- }
- @Before("execution(* com.zeph.aop.Test.reportInPrivateMethod())")
- public void logServiceAccessPrivateMethod() {
- System.out.println("Completed PRIVATE :");
- }
- @Before("execution(* com.zeph.aop.Test.reportInPublicMethod())")
- public void logServiceAccessPublicMethod() {
- System.out.println("Completed PUBLIC: ");
- }
- }
Add Comment
Please, Sign In to add comment