Skip to content

Self autowiring does not work for transactional beans [SPR-16645] #21186

Closed

Description

@spring-projects-issues

Jon Rimmer opened SPR-16645 and commented

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.


Affects: 5.0.4

Reference URL: https://github.com/jonrimmer/spring-self-autowiring-is-broken

Issue Links:

Activity

  1. spring-projects-issues commented on Mar 26, 2018

    @spring-projects-issues
    CollaboratorAuthor

    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?

  2. spring-projects-issues commented on Mar 26, 2018

    @spring-projects-issues
    CollaboratorAuthor

    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!

  3. added
    type: bug
    status: invalid
    in: core
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: corestatus: invalid

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions