AnnotationHandler
@Before: Chạy trước khi method được thực thi
@After: Chạy sau khi method trả về một kết quả
@AfterReturning: Chạy sau khi method trả về một kết quả, lọc lấy kết quả trả về
@AfterThrowing: Chạy khi method xảy ra exception
@Around: Gồm các tất cả các advice trên
@Aspect: Đánh dấu đây là 1 aspect
we will have 2 way:
Available role:
GET http://localhost:8080/get
Role: ADMIN
execute controller from ExampleController
Input :
[Ljava.lang.Object;@24b43f46
Hello admin
Result :null
Unavailable role:
GET http://localhost:8080/get2
FAIl
Available role:
GET http://localhost:8080/get3
Role: ADMIN
execute controller from ExampleController
Hello admin
Available role:
GET http://localhost:8080/set
Role: ADMIN
set function called
Unavailable role:
GET http://localhost:8080/set2
FAIl
if we define @Around all annotation @Before, @After or @AfterReturning @AfterThrowing cannot handle
if we define 2 @Around. it will handle with priority
Available role:
GET http://localhost:8080/get
Role: ADMIN
before catchSpecifyAnnotation
Input :
[Ljava.lang.Object;@1171f831
Hello admin
Result :null
after catchSpecifyAnnotation
Unavailable role:
GET http://localhost:8080/get2
FAIl
Available role:
GET http://localhost:8080/get3
Role: ADMIN
before catchSpecifyAnnotation
Hello admin
after catchSpecifyAnnotation
Available role:
GET http://localhost:8080/set
Role: ADMIN
before executionAnnotation
set function called
after executionAnnotation
Unavailable role:
GET http://localhost:8080/set2
FAIl
add class to implement: ConstraintValidator<AnnotationConfig, String>
with override
public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext);
and add the annotation @Constraint(validatedBy = AnnotationValidate.class)
abnormal case:



