@Qualifier often appear in an interface, a number of implementation class calls in the case, in some choice processing, give the use of examples, realize this kind of beauty.
package spring;import org.springframework.beans.factory.annotation.autowired;import org.springframework.beans.factory.annotation.qualifier;import org.springframework.context.annotation.annotationconfigapplicationcontext;import org.springframework.context.annotation.componentscan;import org.springframework.context.annotation.configuration;import org.springframework.stereotype.component; import javax.annotation.postconstruct;import java.lang.annotation.elementtype;import java.lang.annotation.retention;import java.lang.annotation.retentionpolicy;import Java.lang.annotation.target;import static spring. Spring.platform, @Configuration @componentscanpublic class spring { public static void main (String[] args) { new annotationconfigapplicationcontext (spring.class); } @autowired @Platform (Platform.OperatingSystems.ANDROID) private MarketPlace android; @Autowired @Platform ( Platform.OperatingSystems.IOS) private MarketPlace ios; @PostConstruct public void qualifythetweets () { system.out.println ("ios:" + this.ios); system.out.println ("android:" + this.android); } // the type has to be public! @Target ({ Elementtype.field, elementtype.method, ElementType.TYPE, &nbsP; elementtype.parameter}) @Retention (retentionpolicy.runtime) @Qualifier public static @interface Platform { operatingsystems value (); public static enum OperatingSystems { IOS, android } }}
Interface:
Interface MarketPlace {}
Implementing Class One:
@Component @platform (Platform.OperatingSystems.IOS) class Applemarketplace implements MarketPlace {@Override public S Tring toString () {return ' Apple '; }}
Implementing Class Two:
@Component @platform (Platform.OperatingSystems.ANDROID) class Googlemarketplace implements MarketPlace {@Override pub Lic String toString () {return ' Android '; }}
Spring @Qualifier Example