0

I have one class EmailServiceImpl which implements EmailService and another class ReportServiceImpl which implements ReportService. Both the interfaces are annotated with @EnableAsync, and so there are methods with @Async annotations.

I am using default spring taskexecutor.

I am unable to autowire EmailService inside ReportService.

Please refer to the stacktrace here

sarvagya kumar
  • 121
  • 1
  • 8
  • Stacktrace pls. Async and Autowired shouldn't care about each other. You don't need to enable async support twice but that shouldn't be the issue either. – zapl Jun 03 '16 at 03:59
  • I'm not enabling async twice but spring by default creates proxy to async methods and I can't bypass it. Of course Async and Autowired doesn't care about each other, the problem comes when I'm trying to autowire a already proxied class inside another proxy class. – sarvagya kumar Jun 03 '16 at 04:04
  • "Both the interfaces are annotated with @EnableAsync"? Anyway, do you have a stacktrace or error message for the problem? There should be no reason that proxied classes can't be autowired into other proxied classes: http://stackoverflow.com/a/18995799/995891 – zapl Jun 03 '16 at 04:13
  • Have you read the documentation for `@EnableAsync`? It says that the annotation needs to be used on a `@Configuration` class, not an interface. http://docs.spring.io/spring/docs/4.2.4.RELEASE/javadoc-api/org/springframework/scheduling/annotation/EnableAsync.html – JamesENL Jun 03 '16 at 04:26
  • I have added the Stacktrace screenshot – sarvagya kumar Jun 03 '16 at 06:06

1 Answers1

2

It's working now, I used applicationcontext.getBean("beanName") method to get the bean instead of @Autowired.

sarvagya kumar
  • 121
  • 1
  • 8