Spring Boot : Create a bean only if its dependencies exist -


i have project in spring boot 1.5.2. have bean , create if dependencies created. tested spring autoconfiguration without success , beanfactorypostprocessor. last solution works. wondering better way it. thanks.

edit

i tested spring autoconfiguration below class without success. bean not created :

@configuration @conditionalonbean(value = javamailsender.class) @autoconfigureafter(mailsenderautoconfiguration.class) public class mailautoconfiguration { @bean     public mymailsender createmymailsender() {     return new mymailsender();     } } 

mailautoconfiguration , mymailsender in same package

edit

i found problem. had not seen constraint :

auto-configurations have loaded way only. make sure defined in specific package space , never target of component scan in particular. 

i can use @conditionalonbean


Comments