I believe this should be simple, but I can't figure it out.
I have a configuration class like this:
@Configuration
@AutoConfigureAfter(MailSenderAutoConfiguration.class)
public class MyMailConfiguration {
@Bean
@ConditionalOnBean(JavaMailSender.class)
public MyMailer myMailer(JavaMailSender javaMailSender) {
return new MyMailer(javaMailSender);
}
}
But MyMailer doesn't get created. If I remove the ConditionalOnBean, JavaMailSender gets injected and MyMailer gets created, but I want the condition there so when I don't have the mail configured, it doesn't crash.
The only option left is to use ConditionalOnProperty and watch for the same properties as the MailSenderAutoConfiguration do, but that stinks.