Created
March 9, 2020 10:24
-
-
Save vlytsus/a9b87f6a3d7c0e52e5c78bf8a2411d35 to your computer and use it in GitHub Desktop.
Spring named beans injection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component("email") | |
public class EmailStrategy implements NotificationStrategy { ... } | |
... | |
@Component("sms") | |
public class SmsStrategy implements NotificationStrategy { ... } | |
... | |
@Service | |
public class NotificationService() { | |
@Resource(name = "email") | |
NotificationStrategy notifyEmail; | |
@Resource(name = "sms") | |
NotificationStrategy notifySms; | |
public void sendSMS(message) { | |
notifySms.send(message); | |
} | |
public void sendEmail(message) { | |
notifyEmail.send(message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment