Posts

Showing posts with the label @Qualifier

Spring @Qualifier Annotation Example

Image
In this section we will learn about @Qualifier  Annotation.   The  @Qualifier  annotation is used to resolve the autowiring conflict, when there are multiple beans of same type. If two or more beans of same type declared in the configuration file then autowiring conflict will occur if you use only @Autowired . Annotation based Configuration example : Let's take a  Message Processing  Example - a message can be sent in many ways like email, SMS etc. Create  MessageService   interface for multiple message service implementations -  EmailService , and  SMSService   classes. public interface MessageService { public void sendMessage (); } Create implementations -  EmailService , and SMSService  classes. @Component ( "emailService" ) public class EmailService implements MessageService { @Override public void sendMessage () { System . out .println( "Sending Email" ); } } @Component ( "smsService" ) public class SMSService implements Me