You can't do multiple applicationContext.xml files, but luckily that
isn't really the solution. So in our case - using hibernate and struts
along with spring, we have:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web
Application 2.3//EN" "
http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app id="WebApp">
<filter>
<filter-name>hibernate</filter-name>
<filter-class>org.springframework.orm.hibernate.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>sessionFactoryBeanName</param-name>
<param-value>mySessionFactory</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>hibernate</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>hibernate</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<listener>
<listener-class>com.siemens.swa.session.SessionListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>definitions-config</param-name>
<param-value>/WEB-INF/tiles-defs.xml</param-value>
</init-param>
<init-param>
<param-name>config</param-name>
<param-value>
/WEB-INF/struts-config.xml
</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>validate</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<!-- Inicializando o BeanFactory -->
<servlet>
<servlet-name>ObjectFactoryServlet</servlet-name>
<servlet-class>com.siemens.swa.util.support.ObjectFactoryServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>protected/index.html</welcome-file>
<welcome-file>protected/index.htm</welcome-file>
<welcome-file>protected/index.jsp</welcome-file>
</welcome-file-list>
<session-config>
<session-timeout>10</session-timeout>
</session-config>
<error-page>
<error-code>500</error-code>
<location>/protected/common/openError.jsp</location>
</error-page>
<taglib>
<taglib-uri>/WEB-INF/tld/webmenu.tld</taglib-uri>
<taglib-location>/WEB-INF/tld/webmenu.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/tld/struts-bean.tld</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/tld/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/tld/struts-logic.tld</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-logic.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/tld/struts-bean-el.tld</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-bean-el.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/tld/struts-html-el.tld</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-html-el.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/tld/struts-logic-el.tld</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-logic-el.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/tld/struts-nested.tld</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-nested.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/tld/struts-template.tld</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-template.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/tld/struts-tiles.tld</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-tiles.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/tld/c.tld</taglib-uri>
<taglib-location>/WEB-INF/tld/c.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/tld/swa.tld</taglib-uri>
<taglib-location>/WEB-INF/tld/swa.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>
http://jakarta.apache.org/taglibs/datagrid-1.0</taglib-uri>
<taglib-location>/WEB-INF/tld/taglibs-datagrid.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-tiles.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>
http://java.sun.com/jsp/jstl/functions</taglib-uri>
<taglib-location>/WEB-INF/tld/fn.tld</taglib-location>
</taglib>
<!-- Arquivo de mensagens p/ internacionalizacao-->
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>ApplicationResources</param-value>
</context-param>
<context-param>
<param-name>application</param-name>
<param-value>ApplicationResources</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml
/WEB-INF/actionContext.xml /WEB-INF/serviceContext.xml
/WEB-INF/daoContext.xml</param-value>
</context-param>
</web-app>
Notice the end of the xml - one for a dao, service etc. Note that there
are other motives in the example I give - they have to do with advance
Hibernate topics like lazy loading.
Anyways, so then in our case we have the ObjectFactoryServlet
referenced above which does:
public void init() throws ServletException {
try {
log.info("Carregando BeanFactory no ObjectFactory.");
super.init();
WebApplicationContext wac = WebApplicationContextUtils.
getRequiredWebApplicationContext(getServletContext());
ObjectFactory.setFactory(wac);
} catch (Exception e) {
log.fatal("Não foi possível carregar o BeanFactory no "
+ "ObjectFactory.", e);
}
}
Gotta run, but you can see some of the config files here:
http://www.braziloutsource.com/random/logs
HTH,
iksrazal
http://www.braziloutsource.com/