-
Notifications
You must be signed in to change notification settings - Fork 41k
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
Actuator throws an exception when using prototype scoped DataSource bean #44706
Comments
I'm not sure what you mean by "ignoring properties". Which properties do you believe are being ignored? I would guess it's the properties for the I also don't understand how your application is supposed to work without Actuator. Do you really want a new |
I read that Anyways. The main bug is, that Actuator is trying to instantiate this bean and there's no way to disable that. What is the reason to instantiate a prototype scoped parametrized bean? It would definitely fail, what I observe in this example. |
Sorry, didn't notice the second part of your comment. I just expect/want actuator to ignore this bean as it could not be monitored, of course. Just to support all other metrics except this. The rest of the app instantiates this datasource as described here and everything is working just fine. Till I add actuator. |
Also, you could read more about what Spring devs meant by the "prototype" scope beans here |
Actuator's Given the current capabilities of Framework, your
I can't see any code in your example using Right now, I think your best option may be to not use a |
As I understood from the previous comments and my common understanding of the Spring architecture, there's no reason and no possibility to monitor every instance of the prototype scoped beans at all. Anyways, why actuator is it trying to instantiate it? For what? It would be another instance, not one of those created and used by the app. What is the reason of such a strange behaviour? "would require a change to Spring Framework." I see two possible options here - to document this bug or to fix it. Second would definitely require a change. As every bug fix. It is just my opinion, of course. I understand what workarounds I could use. There are many, starting from the decorator and finished with "do not use spring at all". But I have a bug report, not a question about workarounds. And therefore my first question would be: "do you consider it as a bug, when two documented Spring features ain't working together?" Regarding the mve - my example is focused on the bug, not on the workaround or my app structure. Yes, I do use ObjectProvider#getObject to get instances, but I suppose it is completely unrelated to the bug itself and therefore irrelevant. Although I could add a n example:
but how could it help? |
Actuator is trying to provide metrics for all
We can't process a bug report without fully understanding the problem. I also thought that us having a full understanding of the problem may help us to suggest some workarounds. You've now made it abundantly clear that you have no interest in us helping you to work around the current limitations so I'll stop wasting my time. I'll discuss things with the Framework team to see what our options may be for retrieving all non-prototype beans from the context. |
Well, I've added an example. Please confirm it is enough.
It's clear. I just look a bit dumb, but actually, I'm mostly not. My point is, that there's no sense at all to provide any metrics for prototyped beans instances created internally by actuator, neither parametrized or not. I'd even dare to say that actuator should not create any user objects it has not been asked to.
Workaround is clear - to retrieve datasource in different way, for example from You know, as a developer, I always try to fix my bugs as soon as possible. However, I’m quite familiar with another kind of developers -those who try to prove that "it's not a bug," "there are workarounds," or "provide us with an app that reproduces the bug, with at least 10,000 lines of code," etc. I see no point in wasting time arguing.
The code I initially provided is enough to track the bug. This bug exists even if this prototyped bean is never instantiated, meaning I could provide an empty file as a usage example. But ok, I'll follow. Here's the example. Well. Regarding possible fix: I see here is a good place :
It would be probably the simplest solution to allow to replace this bean with the one provided by the user. So I could filter the map returned by the |
Thank you so much Andy! |
Spring Boot 3.4.3:
Test configuration:
Exception (org/springframework/boot/actuate/autoconfigure/metrics/jdbc/DataSourcePoolMetricsAutoConfiguration$DataSourcePoolMetadataMetricsConfiguration.class):
App properties:
Problem:
Spring Boot Actuator is trying to instantiate a parametrized prototype bean ignoring properties.
Fix:
No need to retrieve beans with scopes other than singleton because it leads to the new bin creation. And there's no scenario exists to monitor beans created by the actuator, not by the app.
Usage example in the app:
The text was updated successfully, but these errors were encountered: