1

I want to use aspect method depending on specific annotation. In my scenario when I mark up my business class with @Service annotation it is not working, but when I change it to component it starts to work.

Here is sample:

  My Aspect class...
        @Aspect
        @Component
        public class MyAspect
        {
        ....
            @Around(value="@annotation(com.myannoation.annotation.MyAnnotate)")
            public Object MyMethod(ProceedingJoinPoint proceedingJoinPoint) throws Exception {
                return ......
            }
    .......

    @Component-->it is work
    @Service -->it is not working
    @Path("api/myapisample")
    public class myapicontroller {


        @POST
        @Produces(MediaType.APPLICATION_JSON)
        public Response confirm(MyRequest request)
        {

.....
Ivan Lymar
  • 2,180
  • 11
  • 26
Bilgehan
  • 1,135
  • 1
  • 14
  • 41
  • Works for me (Spring Boot 2.1.4). What package is the @Service annotation from? – Strelok May 16 '19 at 11:09
  • 2.1.3.RELEASE my version is this. – Bilgehan May 17 '19 at 11:21
  • @Bilgehan, were you able to get this resolved? I'm seeing the same issue. My Aspect works on methods in my controllers, but not on methods in my services. – Woodchuck Nov 03 '22 at 21:46
  • FYI, turns out for me seems to have been that my method was running via a scheduler (Quartz), which for some reason that I'm as yet unclear on seems to ignore the custom aspect with which I had annotated the method. – Woodchuck Nov 04 '22 at 16:40
  • Mycase not related with quartz, I change service to component – Bilgehan Nov 05 '22 at 18:02

0 Answers0