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

Broken injection mechanism #32716

Closed
l3r8yJ opened this issue Apr 26, 2024 · 4 comments
Closed

Broken injection mechanism #32716

l3r8yJ opened this issue Apr 26, 2024 · 4 comments
Labels
for: stackoverflow A question that's better suited to stackoverflow.com

Comments

@l3r8yJ
Copy link

l3r8yJ commented Apr 26, 2024

@jhoeller @sbrannen take a look, please

Who can explain this behavior in Spring:
there is an abstract class

abstract class BaseRepo {
    @Autowired
    protected lateinit var dsl: DSLContext
    // ....
}

@Repository
class MyRepo : BaseRepo {
    // ...
}

question: why in case MyRepo is declared as @Repository, the framework does not initialize @Autowired fields – protected lateinit var dsl: DslContext, but if you change @Repository to @Service or @Component, the injection works? This is strange, because @Repository is a subtype of @Component, just at the specification level, but it turns out not, Spring handles them differently.

P.S.
I noticed it on Spring Boot 3, I haven't tested it on Spring Boot 2. Constructor injection - do not suggest

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Apr 26, 2024
@snicoll
Copy link
Member

snicoll commented Apr 26, 2024

Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use the issue tracker only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.

@snicoll snicoll closed this as not planned Won't fix, can't repro, duplicate, stale Apr 26, 2024
@snicoll snicoll added for: stackoverflow A question that's better suited to stackoverflow.com and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Apr 26, 2024
@l3r8yJ
Copy link
Author

l3r8yJ commented Apr 27, 2024

@snicoll which details I need to add? obviously this issue is a bug, because the unexpected behaviour was described.
Also, SO already contains this question. There is no answer around 7 years. I insist to reopen this issue. So, wdyt?

@snicoll
Copy link
Member

snicoll commented Apr 27, 2024

A sample that demonstrates what you've described that we can clone and run.

Here's one that attempts to reproduce what you've described and it works as expected: https://github.com/snicoll-scratches/demo-32716

There is no answer around 7 years. I insist to reopen this issue. So, wdyt?

That pinging team members and gathering your colleagues to thumb up your issue as soon as it's created is a bit obnoxious. If you provide something that fails the way you've described using only the core spring framework, we can obviously reopen and have a look to it.

@l3r8yJ
Copy link
Author

l3r8yJ commented Apr 27, 2024

@snicoll okay, if I'll create runnable example using Spring Boot it would be possible to move this issue to Spring Boot repository?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: stackoverflow A question that's better suited to stackoverflow.com
Projects
None yet
Development

No branches or pull requests

3 participants