I'm using an API that exposes services in the form of XXXLocalServiceUtil classes which are static wrappers of singleton objects. Instead of using the static XXXLocalServiceUtil methods I want to inject the XXXLocalService objects themselves to use them directly in my code, e.g.:
@Named
public class MyMailingService {
@Inject UserLocalService userService;
public String mailUser(String email) {
User user = userService.getUser(email);
emailUser(user);
}
}
And configure my applicationContext.xml
like so:
<beans ...>
<bean class="x.y.z.UserLocalServiceUtil" factory-method="getService"/>
<bean class="x.y.z.CompanyLocalServiceUtil" factory-method="getService"/>
...
</beans>
This works perfectly. Now, this API I'm talking about has about 100 of these XXXLocalServiceUtil classes, each with their own static getService
method which returns the actual service. Instead of listing all those services in my applicationContext.xml
I would like to let Spring do the magic of finding the right XXXLocalServiceUtil class for each XXXLocalService I inject. So what I need is some kind of dynamic bean factory that will do the work for me, on a lazy-loading basis of course.
Anybody knows how this can be achieved easily?