-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Add fallback option default false to @Qualifier [SPR-13623] #18201
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
Comments
Stéphane Nicoll commented Just to make sure I understand this properly. You'd like that when That looks a bit weird to me and it changes the semantic of |
Yanming Zhou commented If fallback is true and there is no candidate named "customEchoService", It should act as no |
Stéphane Nicoll commented It's still not clear, sorry. It will inject "defaultEchoService" because that's the only bean of type |
Yanming Zhou commented @Qualifier(value = "customEchoService", fallback = true)
@Autowired
private EchoService echoService; is equals to @Autowired
private EchoService echoService; if there is no "customEchoService" |
Stéphane Nicoll commented your "equals to" makes no sense without more context. What if I have two |
Yanming Zhou commented "equals to" means exactly identical. just ignore |
Stéphane Nicoll commented why don't you start with that in your original description rather than having a |
Yanming Zhou commented Should it be resolved in 4.3 ? |
Stéphane Nicoll commented We just discussed this issue and we're not keen on implementing this. This significantly complexify the semantic of |
Yanming Zhou commented Inject the list or map will contaminate clean code. How about add a dedicated annotation? Such like |
Yanming Zhou commented Workaround : @Autowired(required = false)
@Qualifier("cacheStringRedisTemplate")
private RedisTemplate<String, String> cacheStringRedisTemplate;
@Autowired
@Qualifier("stringRedisTemplate")
private RedisTemplate<String, String> stringRedisTemplate;
@PostConstruct
public void afterPropertiesSet() {
if (cacheStringRedisTemplate != null)
stringRedisTemplate = cacheStringRedisTemplate;
} Wish: @Autowired
@Qualifier(value = "cacheStringRedisTemplate", fallback = "stringRedisTemplate")
private RedisTemplate<String, String> stringRedisTemplate; @Autowired
@Qualifier("cacheStringRedisTemplate")
@FallbackQualifier("stringRedisTemplate")
private RedisTemplate<String, String> stringRedisTemplate; @Autowired
@CandidateQualifier("cacheStringRedisTemplate")
@Qualifier("stringRedisTemplate")
private RedisTemplate<String, String> stringRedisTemplate; |
Yanming Zhou opened SPR-13623 and commented
It's identical to current implementation If fallback=false, so it's backward compatible.
fallback=true is useful for override base platform in particular app.
Spring will inject DefaultEchoService as echoService, If we have another EchoService named "customEchoService", spring should inject it instead.
No further details from SPR-13623
The text was updated successfully, but these errors were encountered: