-
Notifications
You must be signed in to change notification settings - Fork 41.1k
@SpyBean and @Transactional and SelfInjection regression in 2.6.4 #30575
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
Comments
Thanks for the report.
Can you please take the time to move all of that in a project that we can clone and run. We'd have to do that anyway and we'd rather focus on the problem at hand rather than copy bits and pieces to a new project. |
Is this ok ?
|
Thanks for the sample, @jonenst. Unfortunately, I'm not sure that it's possible to fix this without regressing the fix for #29909 or introducing a similar problem. I've prototyped something in this branch. The approach that I have taken is to restore the old behavior when raw injection is allowed. It fixes the scenario described in this issue, restoring the behaviour where MyService is spied and a different MyService spy is injected into the MyService spy bean. This is covered by The javadoc for
This is exactly the situation here. There's auto-proxying involved and there's a circular reference as a bean depends upon itself. There's also a note on the javadoc for
Given the apparent difficulty in fixing this in a way that will work for everyone and the recommendations made in Framework, I am inclined to decline this issue. I think our priority should be on I'll flag this for a forthcoming team meeting so that we can discuss this in case the rest of the team disagree. |
Hi, I always thought that self injecting was a legitimate use case (typically for In any case, I'm happy to wait for your decision during your next team meeting. I assume you'll update this issue. |
There's no distinction that I am aware of in Framework between a cycle caused by a bean injecting itself and a larger cycle involving multiple beans. I'd take the need to enable raw injection and the note in its javadoc as a strong signal that you're doing something that's not recommended and is best avoided. spring-projects/spring-framework#28299 will hopefully result in a definitive answer and some recommendations from the Framework team. |
We've discussed this today and we are in agreement. Closing. |
Hi, just to be sure that I understood correctly: when using raw injection, in order to support spybean on two mutually injected beans, you are dropping support for spybean on self injecting beans ? |
Not exactly. We want to tolerate using SpyBean when multiple beans create a cycle that does not require raw injection to be enabled. Beyond that, we do not want to make any changes to support SpyBean with raw injection enabled. It does not appear to be possible to support all scenarios and flip-flopping from one to the other as issues are raised isn’t a viable option, particularly given the recommendations against using raw injection in the first place. |
Thank you for taking the time to clarify this |
Hi, when using @SpyBean on a transactional (proxied) bean that uses self injection (to have transaction semantics for inner calls), everything works on 2.6.3, but on 2.6.4 the bean in the test is not the mockito mock anymore, so calling mockito mocks method fail.
Maybe a regression from #29909 ?
Edit: see repro below.
The text was updated successfully, but these errors were encountered: