0

in my application i am using AOP on the Controller and DAO Layer - it works properly.

However, on my service layer, which is created inside a @Configuration class (as a bean), it does not work.

So my problem is that the pointcuts and advices for Controller and DAO layer work - but not for the Service Layer.

Reading on the internet - i found out that i should add @EnableAspectJAutoProxy annotation - but it still does not work with this.

Side NOTE:

@Bean("nameOfResolver")
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE, proxyMode = ScopedProxyMode.TARGET_CLASS) 

The class that does not work is like this

public class ResolveImpl implements Resolve {

private static final Logger LOGGER = LoggerFactory.getLogger(ResolveImpl.class);

@CustomAnnotation(user = "user")
public TestClass createTestClass(String user) {
    ......
    }
}

I have this in my bean which resolves which bean should be returned.

Thanks a lot for your help

sem10
  • 556
  • 9
  • 19
  • Show class in service layer that it doesn't work – user7294900 Dec 13 '18 at 14:18
  • i have edited the post to show the service layer (with changed names) – sem10 Dec 13 '18 at 14:22
  • Did you add `@Service` to class? how it's managed by Spring? – user7294900 Dec 13 '18 at 14:24
  • i have added @Service to the Interface of the Service Class but still the same problem. It is managed by this Configuration class which defines the bean and returns it to the 'Autowired' in the Resource layer. – sem10 Dec 13 '18 at 14:27
  • Should be on implementation class `ResolveImpl`, see https://stackoverflow.com/questions/16351780/where-should-service-annotation-be-kept-interface-or-implementation/33530450#33530450 – user7294900 Dec 13 '18 at 14:30
  • No, this is no the problem. I put it there and i get the same behavior – sem10 Dec 13 '18 at 14:39

1 Answers1

0

Ok i finally found the solution to my problem. Since Spring AOP uses proxying mechanisms, i have a method that calls the @CustomAnnotation(user = "user") method which is in the same class. This causes the proxying mechanism not to be triggered. Check Spring AOP not working for method call inside another method for explanation

sem10
  • 556
  • 9
  • 19
  • Which is exactly why you should always share an [MCVE](http://stackoverflow.com/help/mcve) in your questions and not just incoherent code snippets containing what **you** think are the key parts of the problem. If you have a problem and do not know the answer, please enable **others** (the ones you want help from) to decide by showing something compileable and executeable, reproducing the problem. Nobody but you would have had the chance to answer this question but yourself in this case. – kriegaex Dec 15 '18 at 01:29