-
Notifications
You must be signed in to change notification settings - Fork 925
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
Resolve ParameterNameDiscoverer
Bean Conflict in spring-boot-autoconfigure
#10105
Resolve ParameterNameDiscoverer
Bean Conflict in spring-boot-autoconfigure
#10105
Conversation
I'm not sure that adding the @Bean
@ConditionalOnMissingBean
ParameterNameDiscoverer parameterNameDiscoverer() {
return new DefaultParameterNameDiscoverer();
} my guess would be that the original intent was that user can override this bean by creating their own |
Thank you for your feedback.
I understand the intention of this design, I didn't realized that. Actually, it wouldn't work as expected if the I guess the root cause of this issue is
but this either breaks the backward compatibility, right? Accordingly, I suppose there are three ways to address on this issue. 1. Don't make changeWe will attempt to resolve the issue by making adjustments on the client side, without incorporating the changes included like in this pull request. @Configuration
public class OpenTelemetryConfig {
@Bean
@Primary
ParameterNameDiscoverer parameterNameDiscoverer() {
return new DefaultParameterNameDiscoverer();
}
} The advantage of this method is that it completely maintains backward compatibility. However, a potential issue is that if there are other classes requiring the 2. Make a change like in this case to add the
|
so will adding the |
For my understanding today, Allowing the injection of a custom For some Spring versions, So, I would prefer something like this (less code and complexity than with public class InstrumentationAnnotationsAutoConfiguration {
private final ParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer(); |
f995adf
to
4645a10
Compare
@laurit @jeanbisutti, I appreciate your suggestions. From my understanding, it is uncommon (or unexpected) for users to override the implemented instance of According to my understanding, I made that change at a139db8, what do you think about that? |
…onfigure` This update addresses a conflict arising in the `spring-boot-autoconfigure` project when using `opentelemetry-spring-boot-starter` and other projects which use the `ParameterNameDiscoverer` bean simultaneously, e.g. `springdoc-openapi-starter-webmvc-ui`. The issue occurs due to the presence of multiple candidates for the `ParameterNameDiscoverer` object, leading to an injection conflict. When both starters are used together, the application fails to start, displaying an error related to the ParameterNameDiscoverer object. This is due to the ambiguity in selecting the correct bean to inject, as multiple candidates are present. Example of the error output: ``` *************************** APPLICATION FAILED TO START *************************** Description: Parameter 1 of method otelInstrumentationWithSpanAspect in io.opentelemetry.instrumentation.spring.autoconfigure.instrumentation.annotations.InstrumentationAnnotationsAutoConfiguration required a single bean, but 2 were found: - parameterNameDiscoverer: defined by method 'parameterNameDiscoverer' in class path resource [io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/annotations/InstrumentationAnnotationsAutoConfiguration.class] - localSpringDocParameterNameDiscoverer: defined by method 'localSpringDocParameterNameDiscoverer' in class path resource [org/springdoc/core/configuration/SpringDocConfiguration.class] Action: Consider marking one of the beans as @primary, updating the consumer to accept multiple beans, or using @qualifier to identify the bean that should be consumed ``` To resolve this issue, this commit defines the private final `ParameterNameDiscoverer` instance and use that directly instead of injection in `InstrumentationAnnotationsAutoConfiguration`. Signed-off-by: moznion <moznion@mail.moznion.net>
4645a10
to
a139db8
Compare
This update addresses a conflict arising in the
spring-boot-autoconfigure
project when usingopentelemetry-spring-boot-starter
and other projects which use theParameterNameDiscoverer
bean simultaneously, e.g.springdoc-openapi-starter-webmvc-ui
.The issue occurs due to the presence of multiple candidates for the
ParameterNameDiscoverer
object, leading to an injection conflict.When both starters are used together, the application fails to start, displaying an error related to the ParameterNameDiscoverer object. This is due to the ambiguity in selecting the correct bean to inject, as multiple candidates are present.
Example of the error output:
To resolve this issue, the@Qualifier
annotation has been added to the ParameterNameDiscoverer bean within the spring-boot-autoconfigure project. This annotation assigns a unique label to the ParameterNameDiscoverer bean, ensuring that the project-specific bean is consistently chosen for injection, thereby eliminating the conflict.Update:
To resolve this issue, this commit defines the private static
ParameterNameDiscoverer
instance and use that directly instead of injection inInstrumentationAnnotationsAutoConfiguration
.