Fri 18 Aug 2006
Spring Recipe #2: Spring-backed Factory
Posted by dkaz under Java, Programming
If you would like Spring to do the heavy-lifting for your Factory class, you can simply inject ApplicationContext into your factory and delegate your create() methods to Spring’s getBean() methods.
public class YourServiceFactory implements ApplicationContextAware {
private ApplicationContext context;
public void setApplicationContext(ApplicationContext context) {
this.context= context;
}
public YourService createYourService() {
return (YourService ) context.getBean(serviceName);
}
}
One Response to “ Spring Recipe #2: Spring-backed Factory ”
Comments:
Leave a Reply
Trackbacks & Pingbacks:
-
Pingback from Technical Related Notes » Blog Archive » links for 2006-08-19
August 21st, 2006 at 7:59 pm[…] Spring Recipe #2: Spring-backed Factory ยป STRAY neuron […]
