I have myannotation and whenever my method(which has myannotation) is executed then AOP should be called but which is not working in my spring boot controller.But which is working for methods which has other annotations.Please help me to understand about what happens.
Update: MyAnnotation
Код: Выделить всё
@Retention(RUNTIME)
@Target({ METHOD, CONSTRUCTOR })
public @interface MyAnnotation {
}
@Aspect
@Component
public class AnnotationAspect {
private static final String POINTCUT_METHOD1 = "@annotation(com.somepackage.MyAnnotation)";
@Around(POINTCUT_METHOD1)
public Object weaveJoinPoint(ProceedingJoinPoint joinPoint) throws Throwable {
try {
System.out.println("Beforeee " + joinPoint);
joinPoint.proceed();
} finally {
System.out.println("Afterrr " + joinPoint);
}
return null;
}
}
Код: Выделить всё
@Controller
@RequestMapping("user")
public class ArticleController {
@GetMapping("article/{id}")
@MyAnnotation // here it is
public ResponseEntity getArticleById(@PathVariable("id") Integer id)
{
return new ResponseEntity(dummyMethod(), HttpStatus.OK);
}
public String dummyMethod() {
System.out.println("Dummy method with MyAnnotation");
return "HelloWorld!";
}
}
Код: Выделить всё
Beforeee execution(ResponseEntity com.mypackage.getArticleById(Integer))
Dummy method with MyAnnotation
Afterrr execution(ResponseEntity com.mypackage.getArticleById(Integer))
Код: Выделить всё
@Controller
@RequestMapping("user")
public class ArticleController {
@GetMapping("article/{id}")
public ResponseEntity getArticleById(@PathVariable("id") Integer id)
{
return new ResponseEntity(dummyMethod(), HttpStatus.OK);
}
@MyAnnotation //here it is
public String dummyMethod() {
System.out.println("Dummy method with MyAnnotation");
return "HelloWorld!";
}
}
Код: Выделить всё
Dummy method with MyAnnotation
Код: Выделить всё
@Service
public class ArticleService {
@MyAnnotation //here it is
public String dummyMethod() {
System.out.println("Dummy method with MyAnnotation");
return "HelloWorld!";
}
}
Источник: https://stackoverflow.com/questions/512 ... pring-boot