Module Application Context File
This file allows modules to override/append to the current spring application context definition. It must be named moduleApplicationContext.xml and be located in the omod resources folder (mavenized modules) or the metadata folder (ant task modules).
If you have an ant task module and wish to provide a clean separation between your API- and Web-layer mappings, you can do this by putting your API-layer mappings in moduleApplicationContext.xml and your Web-layer mappings in webModuleApplicationContext.xml.
The doctype should be set to that of the current spring library's doctype. Currently, that is
<\!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
The mapping file must have a unique id associated with it.
In order to create your own module's service, the following bean must be used. This is unfortunately a lot of xml code to write, but there isn't a way around it. There are only a few tags at which values need to be manipulated:
<bean parent="serviceContext">
<property name="moduleService">
<list>
<value>org.openmrs.module.formentry.FormEntryService</value> <!-- Your service's interface class -->
<bean class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager"><ref bean="transactionManager"/></property>
<property name="target">
<bean class="org.openmrs.module.formentry.impl.FormEntryServiceImpl"> <!-- Your service's concrete class -->
<property name="formEntryDAO"> <!-- Name of the DAO property on your ServiceImpl -->
<bean class="org.openmrs.module.formentry.db.hibernate.HibernateFormEntryDAO"> <!-- Your DAO's concrete class -->
<property name="sessionFactory"><ref bean="sessionFactory"/></property>
</bean>
</property>
</bean>
</property>
<property name="preInterceptors">
<ref bean="serviceInterceptors" />
</property>
<property name="transactionAttributeSource">
<bean class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource"/>
</property>
</bean>
</list>
</property>
</bean>
Redirects can be defined with this file. If we have a file in our formEntry module's web folder named formTaskpane.jsp. Without anything added to the spring context file, this could only be accessed via /openmrs/module/formEntry/formTaskpane.htm. However, if we add a mapping for this file like:
<bean id="formEntryUrlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="**/formTaskpane.htm">formTaskpaneRedirect</prop>
</props>
</property>
</bean>