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
Added resolving beans by type #695
Added resolving beans by type #695
Conversation
...boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptidePostProcessor.java
Show resolved
Hide resolved
I believe we have a couple of other places where this could be useful. Basically whenever we inject by name right now. Logbook comes to mind, e.g. |
Another way that came into my mind: register factories in postProcessBeanDefinitionRegistry and afterwards configure them in postProcessBeanFactory. This seems to be the most API-friendly way of solving the problem, but will require a lot(?) of changes in initialisation |
And
We have two kinds of configuration. Some of them completely disable a bean and others really just configure it. So we would need to spread this across both. |
I would propose following:
If this sounds fine for you I'll start working on implementation.
I don't get this point. What do you mean by two kinds of configuration? Any sample in the code? |
riptide.clients.example:
tracing:
enabled: true
tags:
peer.service: example-service The So the configuration affects both the registration and wiring of beans as well as the configuration of the properties of said beans. |
Looking forward to some code to discuss this further! 🎉 |
This reverts commit afd2b18.
While implementing a lot of factories, I just recognised that we don't actually require that. So there's a lot more simplified approach. I haven't changed yet the metricsRegistry yet, since it leads to broken tests, and I want to figure out reasons for this behaviour. |
bd.getConstructorArgumentValues() | ||
.getIndexedArgumentValues() | ||
.values().stream() | ||
.filter(holder -> arg.equals(holder.getValue())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That feels risky.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep. There's two options:
- rely on position index.
- Use a cryptic constant for default value similar to https://github.com/spring-projects/spring-framework/blob/3a0f309e2c9fdbbf7fb2d348be861528177f8555/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/ValueConstants.java#L34
So with moving away from fixed name strategy, appropriate bean resolving will happen based on |
...-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/DefaultRiptideConfigurer.java
Outdated
Show resolved
Hide resolved
...-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/DefaultRiptideConfigurer.java
Show resolved
Hide resolved
...-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/DefaultRiptideConfigurer.java
Outdated
Show resolved
Hide resolved
@@ -40,7 +40,8 @@ public void postProcessBeanDefinitionRegistry(final BeanDefinitionRegistry regis | |||
|
|||
@Override | |||
public void postProcessBeanFactory(final ConfigurableListableBeanFactory beanFactory) throws BeansException { | |||
// nothing to do | |||
final DefaultRiptideConfigurer configurer = new DefaultRiptideConfigurer(beanFactory, Defaulting.withDefaults(properties)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Defaulting.withDefaults(properties)
can be done once in setEnvironment
...pring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/ValueConstants.java
Show resolved
Hide resolved
👍 |
@whiskeysierra while I was describing the changes in migration guide, something struck in my mind. Afaik if multiple beans of the same type present in spring context, but no primary explicitly defined I think spring will fail the context init. But last time I saw this behaviour was somewhere during initial release of spring 4, and not sure if it's current one. Should we follow this behaviour as well here, instead of injection of the first random bean? |
I believe Spring tries to fallback to injecting by name. If that fails is usually complains about non-unique beans. Ideally we would hand over all of this work to Spring. |
Switched to default spring behaviour: try to find primary bean, if not found use resolve by name. |
You're missing some code coverage there. |
👍 |
Description
Inject tracer by bean reference instead of name
Motivation and Context
Currently tracer bean is injected by name. This leads to incompatibility issues with tracing-lightstep-spring-boot-starter > 0.1.5
Instead of relying on bean name for plugin registration, I've changed to loading by type.
Types of changes
Checklist: