Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scheduled method is not invoked via proxy [SPR-13914] #18488

Open
spring-projects-issues opened this issue Feb 3, 2016 · 5 comments
Open

Scheduled method is not invoked via proxy [SPR-13914] #18488

spring-projects-issues opened this issue Feb 3, 2016 · 5 comments
Labels
in: core type: bug

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Feb 3, 2016

Mitchell Bosecke opened SPR-13914 and commented

I have several methods annotated with @scheduled and the majority of them run just fine but one of them in particular is not invoked via a proxy, it is invoked directly. The method is on a class annotated with @Service and @Transactional and that class has an appropriate interface with the method signature on it; i.e. I'm using JDK dynamic proxies.

The @scheduled annotation is on the implementation of the method. There is nothing unique about this method compared to my other @scheduled methods as far as I can tell.

That exact same method, when invoked via a web endpoint works as expected (via proxy and a transaction is available).

I've included some example code in the linked stack overflow post; let me know if I should copy some of that here.


Affects: 3.2.16

Reference URL: http://stackoverflow.com/questions/35184189/spring-scheduled-method-not-invoked-via-proxy-therefore-no-transaction

Issue Links:

  • #20469 EnableAsync prevents EnableCaching from working in self-injection scenarios
  • #18389 Consistent validation of annotated methods behind AOP proxies
  • #18226 @EventListener does not work if put it at method in class that implements interface
@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Feb 3, 2016

Juergen Hoeller commented

Could you please try this against 4.2.4 which has several refactorings over the 3.2.x algorithm for discovering annotated methods there? And current 4.3 snapshots take this even further...

Juergen

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Feb 3, 2016

Mitchell Bosecke commented

I was able to try it against both 4.2.4 as well as the 4.3.0 snapshot and I'm still encountering the same issue.

Is there anything short of a fully functional test case that I can provide? I'm worried that will be difficult for me to create because I don't know what is unique about this one particular scheduled method (and it is a small part of a very large application).

Thanks for your assistance; it is very much appreciated.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jan 17, 2017

Dmitry Savichev commented

I have encountered this issue today with 4.2.6. I believe that the cause behind this issue is that the bean with @Scheduled method is autowired somewhere without being wrapped in a proxy (or before it is wrapped by a proxy?). Because of that the bean itself and not the proxy is picked up by ScheduledAnnotationBeanPostProcessor.

It is possible to work around this issue by moving @Scheduled methods into a separate singleton-scoped bean.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Nov 2, 2017

Leonardo De Santis commented

Hi everyone, the issue is still present in version "4.3.5.RELEASE". I guess a lot of people wasted a lot of time on this, can we expect a fix anytime soon?

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Nov 2, 2017

Juergen Hoeller commented

This might be caused by an effect similar to #20469 where early injection (possibly self-injection) causes a shortcut where the proxy isn't always present, so ScheduledAnnotationBeanPostProcessor doesn't reliably see it.

A reproducible test would be great here. It's still unclear what the exact circumstances are.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core type: bug
Projects
None yet
Development

No branches or pull requests

1 participant