Ok thank you Wouter. Actually I found a solution and as I think it might be useful to anyone trying to integrate AndroMDA Spring cartridge with a web application, here it is (might be added as a patch to Spring cartridge).
The problem was that OpenSessionInViewFilter (which is very useful to prevent lazy loading exceptions in web tier) is not flexible enough to accept the structure of Spring configuration files generated by Spring cartridge, that is one beanRefFactory bean with separate applicationContext-datasource and applicationContext inside. By default, org.springframework.orm.hibernate.support.OpenSessionInViewFilter expects sessionFactory bean in root application context so with the following usual web.xml configuration : <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/classes/beanRefFactory.xml</param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <filter> <filter-name> OpenSessionInViewFilter </filter-name> <filter-class> org.springframework.orm.hibernate.support.OpenSessionInViewFilter </filter-class> <init-param> <param-name>singleSession</param-name> <param-value>false</param-value> </init-param> </filter> <filter-mapping> <filter-name>OpenSessionInViewFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> The webapp initialization went right but on the first request PAF "Code 500 Internal Server Error" because of course sessionFactory bean is not defined in beanRefFactory.xml And the only flexibility allowed by OpenSessionInViewFilter is to specify a custom name for the sessionFactory bean, but no custom "path". So I had to extend OpenSessionInViewFilter and override lookupSessionFactory() method, which gives : package org.epseelon.andromda.utils; import net.sf.hibernate.SessionFactory; import org.springframework.beans.factory.BeanFactory; import org.springframework.orm.hibernate.support.OpenSessionInViewFilter; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; /** * This class extends OpenSessionInViewFilter to take into account the particular Spring * configuration files structure generated by AndroMDA, that is one root beanRefFactory application * context with separated datasource and common beans sub-application contexts. * @author S�bastien Arbogast */ public class OpenSessionInViewFilterForAndromda extends OpenSessionInViewFilter { /** * @see org.springframework.orm.hibernate.support.OpenSessionInViewFilter#lookupSessionFactory() */ protected SessionFactory lookupSessionFactory() { // TODO Raccord de m�thode auto-g�n�r� //return super.lookupSessionFactory(); if (logger.isDebugEnabled()) { logger.debug("Using session factory '" + getSessionFactoryBeanName() + "' for OpenSessionInViewFilterForAndromda"); } WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext()); BeanFactory bf = (BeanFactory)wac.getBean("beanRefFactory"); return (SessionFactory) bf.getBean(getSessionFactoryBeanName()); } } Then I just had to change the filter class in web.xml and now everything works great. -- S�bastien Arbogast _________________________________________________________ Reply to the post : http://galaxy.andromda.org/forum/viewtopic.php?p=95#95 ------------------------------------------------------- This SF.Net email is sponsored by Oracle Space Sweepstakes Want to be the first software developer in space? Enter now for the Oracle Space Sweepstakes! http://ads.osdn.com/?ad_id=7393&alloc_id=16281&op=click _______________________________________________ Andromda-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/andromda-user
