You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Self autowiring does not work for transactional beans [SPR-16645] #21186
The ability for beans to self autowire was added in: #13096
However, this does not work if the bean to self wire is transactional, e.g. has at least one method annotated with @transactional when transactions are enabled.
See the linked GitHub project for a very simple reproduction.
From a quick look at your sample, it looks you're dereferencing a nested field on the self-injected service proxy: That won't work since you'll get a CGLIB proxy with uninitialized fields that you're not supposed to access on the proxy instance. You have to go through public non-final methods there which the proxy can actually intercept.
That said, why are you even dereferencing that field on the proxy to begin with? Only the service proxy itself has transactionally decorated methods: If you're calling methods on a nested delegate there, those won't be transactional in any case. Or am I missing something?
Activity
spring-projects-issues commentedon Mar 26, 2018
Juergen Hoeller commented
From a quick look at your sample, it looks you're dereferencing a nested field on the self-injected service proxy: That won't work since you'll get a CGLIB proxy with uninitialized fields that you're not supposed to access on the proxy instance. You have to go through public non-final methods there which the proxy can actually intercept.
That said, why are you even dereferencing that field on the proxy to begin with? Only the service proxy itself has transactionally decorated methods: If you're calling methods on a nested delegate there, those won't be transactional in any case. Or am I missing something?
spring-projects-issues commentedon Mar 26, 2018
Jon Rimmer commented
Ah, yes. I see now. The non-sample code was calling a method on the injected self reference, but it wasn't public, so wasn't proxied. Sorry!