0 day streak
java / beginner
Snippet

Resolving Beans with @Qualifier

When multiple beans of the same type exist, @Qualifier tells Spring exactly which one to inject. This avoids ambiguity errors during application startup.

snippet.java
java
1
2
3
@Autowired
@Qualifier("cloudStorage")
private StorageService storage;
spring
Breakdown
1
@Autowired
Requests Spring to inject a matching dependency.
2
@Qualifier("cloudStorage")
Specifies the unique name of the bean to be used.