/
Module Creator's Cheat Sheet
Module Creator's Cheat Sheet
You should no longer need the config snippets on this page.
The Maven module creation archetype will generate all these configuration snippets for you.
The @Controller, @Component, and @RequestMapping annotations will ensure Spring automatically registers them without config file entries.
Various things you might want to copy-and-paste while creating a module.
config.xml (common values)
<updateURL>https://modules.openmrs.org/modules/download/@MODULE_ID@/update.rdf</updateURL>
<require_modules>
<require_module>org.openmrs.module.htmlformentry</require_module>
</require_modules>
<mappingFiles>
AccountRequest.hbm.xml
</mappingFiles>
<messages>
<lang>en</lang>
<file>messages.properties</file>
</messages>
moduleApplicationContext.xml (minimal with annotation-driven MVC)
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-2.0.xsd">
<context:component-scan base-package="@MODULE_PACKAGE@" />
</beans>
moduleApplicationContext.xml (minimal with old-style MVC)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<!-- Beans to add to the current Application context definition -->
<beans>
<bean id="@MODULE_ID@UrlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="order"><value>1</value></property>
<property name="mappings">
<props>
<prop key="module/@MODULE_ID@/something.form">someController</prop>
</props>
</property>
</bean>
<bean id="someController" class="@MODULE_PACKAGE@.web.controller.SomeController">
<property name="sessionForm"><value>false</value></property>
<property name="commandName"><value>command</value></property>
<property name="formView"><value>/module/@MODULE_ID@/someList</value></property>
<property name="successView"><value>someForm.list</value></property>
</bean>
</beans>
moduleApplicationContext service creation
<bean parent="serviceContext">
<property name="moduleService">
<list>
<value>@MODULE_PACKAGE@.___Service</value> <!-- service interface name -->
<bean class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager"><ref bean="transactionManager"/></property>
<property name="target">
<bean class="@MODULE_PACKAGE@.impl.___ServiceImpl">
<property name="___DAO">
<bean class="@MODULE_PACKAGE@.db.hibernate.Hibernate___DAO">
<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>
Form controller annotations
@RequestMapping("/module/@MODULE_ID@/urlToMap")
Sqldiff.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqldiff PUBLIC "-//OpenMRS//DTD OpenMRS SQL Diff Config 1.0//EN" "http://resources.openmrs.org/doctype/sqldiff-1.0.dtd">
<sqldiff version="1.0">
<help></help>
<diff>
<version>0.1</version>
<author></author>
<date>Jan 1st 2009</date>
<description>
</description>
<sql>
</sql>
</diff>
</sqldiff>
, multiple selections available,
Related content
Module Portlets
Module Portlets
Read with this
Bundled Modules
Bundled Modules
Read with this
Module Dependencies
Module Dependencies
Read with this
Module Config File
Module Config File
Read with this
Community Modules
Community Modules
Read with this
Core Modules
Core Modules
Read with this