This is a how I do it as well as a should I do it question.
I have a case where I need to use instances managed by Spring in a Lambda function.
In short I want DummyBranch, MandrillBranch objects and other branches to be managed by Spring.
public class QOSStrategy {
public static Function<DistributionMessage, List<Feedback>> executeQOS = (message)-> {
QOSFilters qosFilters = new QOSFilters();
List<Branch> providers = qosFilters.getProviderByQOs(message,
Arrays.asList(new DummyEmailBranch(),
new MandrillBranch(),
new EverbrideBranch(),
new JavaMailBranch(),
new DirectSMSBranch()));
}
}
One option I see is to get it from the Spring application-context. But is there a way to do it using Annotations.
Thanks -Parshu
You can autowire Collection of all beans which implement the same interface.
See Spring documentation here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With