Guest User

Untitled

a guest
Dec 17th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. @Component
  2. public class Test{
  3.  
  4. public void reportInPrivateMethod() {
  5. System.out.println("private method");
  6.  
  7. }
  8.  
  9. public void reportInPublicMethod() {
  10. System.out.println("public method");
  11.  
  12. }
  13. }
  14.  
  15. @Component
  16. public class ScheduledTasks {
  17.  
  18. @Autowired
  19. private Test test;
  20.  
  21. private static final Logger log = LoggerFactory.getLogger(ScheduledTasks.class);
  22.  
  23. private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
  24.  
  25. @Scheduled(fixedRate = 5000)
  26. public void reportCurrentTime() {
  27. test.reportInPrivateMethod();
  28. test.reportInPublicMethod();
  29. log.info("The time is now {}", dateFormat.format(new Date()));
  30. }
  31.  
  32.  
  33. }
  34.  
  35. @Aspect
  36. @Component
  37. public class Monitor {
  38.  
  39. @Before("execution(* com.zeph.aop.ScheduledTasks.reportCurrentTime())")
  40. public void logServiceAccess(JoinPoint joinPoint) {
  41. System.out.println("Completed: " + joinPoint);
  42. }
  43.  
  44. @Before("execution(* com.zeph.aop.Test.reportInPrivateMethod())")
  45. public void logServiceAccessPrivateMethod() {
  46. System.out.println("Completed PRIVATE :");
  47. }
  48.  
  49. @Before("execution(* com.zeph.aop.Test.reportInPublicMethod())")
  50. public void logServiceAccessPublicMethod() {
  51. System.out.println("Completed PUBLIC: ");
  52. }
  53. }
Add Comment
Please, Sign In to add comment