Hi all.
Using Spring across an API layer that is meant for use in both the Web and EJB layers. I have a collection of DAO's managed by the Spring container, and I want to correctly manage the instance of the ApplicationContext so that it is created and the config parsed only once. I have seen in the documentation (and Rod's book) that falling back to the singleton in this case may make sense. I am wondering if I can have a POJO factory class which wrapps a static BeanFactory:
Any issues with this approach? Do I need to wrap the DAOFactory as a singleton as well?Code:public class DAOFactory { private static ApplicationContext context; public DAOFactory() { } static { try { context = new ClassPathXmlApplicationContext("app-config.xml"); } catch (Exception ex) { ex.printStackTrace(); } } protected BeanFactory getBeanFactory() { return context; } public Object getBean(String name) { return getBeanFactory().getBean(name); } public UserDAO getUserDAO() { return (UserDAO).getBean("UserDAO"); }


Reply With Quote