'Spring default bean candidate
I'm writing a library that uses spring, for others to use. In my library, I have class A that has an interface B as a field (with @Autowired).
I have a default implementation of that field, but the user can implement a custom implementation by himself. What I want to happen is the following:
If the user implemented B, I want that bean to be injected to A, otherwise I want my default implementation to be injected.
Something like the opposite of @Primary
I know that the user can add the @Primary annotation in order for that to happen, but I don't want him to add any other annotation besides @Component (because it is not clear for the user why he must add the @Primary annotation)
Is there a way to achieve this behavior? I've also tried @Order and @Priority, but no luck - the user must add another annotation.
Thanks!
Solution 1:[1]
I don't believe so. Spring's @Autowired is rather specific. Making it perform differently without any configuration changes (either to XML or the Spring configuration class) is pretty much impossible.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Yserbius |
