Hello Dan,
Happy New Year, the best for 2026.
Really wanted to say thanks for your videos from YouTube, they are easy to follow, instructive, and fun to watch.
Especially this video: https://www.youtube.com/watch?v=yh760wTFL_4
I am one of your subscriber and would like to reach out with a question.
I have the same, a MessageService interface.
Likewise, I have an EmailMessageService and a SmsMessageService, which implement the interface.
The difference is that I have a class which looks like this:
public enum MessageType{
SMS,
EMAIL,
}
And via property, I will do something like:
myapp:
messageType: SMS
or
myapp:
messageType: EMAIL
In your example:
public class MessageServiceRegistrar implements BeanRegistrar {
@Override
public void register(BeanRegistry registry, Environment env) {
String messageType = env.getProperty("app.message-type", "email");
switch (messageType.toLowerCase()) {
case "email" -> registry.registerBean("messageService",
EmailMessageService.class,
spec -> spec.description("Email service via BeanRegistrar"));
case "sms" -> registry.registerBean("messageService",
SmsMessageService.class,
spec -> spec.description("SMS service via BeanRegistrar"));
}
}
}
It seems it is only possible via the environment.
How to do the same with the application properties, application yaml, please?
Hello Dan,
Happy New Year, the best for 2026.
Really wanted to say thanks for your videos from YouTube, they are easy to follow, instructive, and fun to watch.
Especially this video: https://www.youtube.com/watch?v=yh760wTFL_4
I am one of your subscriber and would like to reach out with a question.
I have the same, a MessageService interface.
Likewise, I have an EmailMessageService and a SmsMessageService, which implement the interface.
The difference is that I have a class which looks like this:
And via property, I will do something like:
In your example:
It seems it is only possible via the environment.
How to do the same with the application properties, application yaml, please?