[ http://thecla.homeftp.net:8380/jira/browse/SPRING-36?page=history ] Work on SPRING-36 started by Chad Brandon
> Give access to Spring ApplicationContext singleton > -------------------------------------------------- > > Key: SPRING-36 > URL: http://thecla.homeftp.net:8380/jira/browse/SPRING-36 > Project: Spring Cartridge > Type: Improvement > Reporter: Johnny Macchione > Assignee: Chad Brandon > Priority: Minor > > > When using EJBs, the following files are generated: > - applicationContext.xml > - beanRefFactory.xml > - mypackage.ServiceLocator > The latter references the applicationContext.xml file and is used by the > ContextSingletonBeanFactoryLocator to locate one or more XML application > context definition files, instantiate one or more ApplicationContexts from > these files and make these accessible throughout the application. > The ContextSingletonBeanFactoryLocator is used within EJB implementations to > locate POJO service beans to which the business logic is delegated. > The web tier uses the ServiceLocator to transparently lookup the session EJB > instances from the JNDI context. > Everything is fine in this case. > When not using EJBs at all, only the following files are generated: > - applicationContext.xml > - mypackage.ServiceLocator > The ServiceLocator is now also responsible for locating an XML application > context definition file and instantiate an ApplicationContext. > But in order to keep the interface unchanged with regards to the > ServiceLocator generated when using EJBs, the ApplicationContext getContext() > method is kept protected. > This makes it impossible to access the ApplicationContext instance from > outside mypackage, e.g. to use it as parent context for a new application > context. > I suggest leveraging Spring's ContextSingletonBeanFactoryLocator in the same > way it is used with EJBs and implement the ServiceLocator to use the > ContextSingletonBeanFactoryLocator singleton like this: > beanRefFactory.xml: > <beans> > <bean id="mypackage.applicationContext" > > class="org.springframework.context.support.ClassPathXmlApplicationContext"> > <constructor-arg> > <list> > <value>mypackage/applicationContext.xml</value> > </list> > </constructor-arg> > </bean> > </beans> > ServiceLocator: > private BeanFactoryReference beanFactoryRef; > synchronized ApplicationContext getContext() { > if (beanFactoryRef == null) > { > BeanFactoryLocator beanFactoryLocator = > > ContextSingletonBeanFactoryLocator.getInstance("beanRefFactory.xml"); > beanFactoryRef = beanFactoryLocator.useBeanFactory( > "mypackage.applicationContext"); > } > return (ApplicationContext) beanFactoryRef.getFactory(); > } > public synchronized void dispose() { > if (beanFactoryRef != null) { > beanFactoryRef.release(); > } > } -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://thecla.homeftp.net:8380/jira/secure/Administrators.jspa - If you want more information on JIRA, or have a bug to report see: http://www.atlassian.com/software/jira ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click _______________________________________________ Andromda-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/andromda-devel
