diff --git a/omod/src/main/java/org/openmrs/module/spa/spring/SpaBeanPostProcessor.java b/omod/src/main/java/org/openmrs/module/spa/spring/SpaBeanPostProcessor.java new file mode 100644 index 0000000..1495ead --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/spa/spring/SpaBeanPostProcessor.java @@ -0,0 +1,27 @@ +package org.openmrs.module.spa.spring; + +import org.openmrs.module.spa.SpaResourceConverter; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.BeanPostProcessor; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; + +public class SpaBeanPostProcessor implements BeanPostProcessor, ApplicationContextAware { + + private ApplicationContext applicationContext; + + @Override + public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { + if (bean instanceof RequestMappingHandlerAdapter) { + RequestMappingHandlerAdapter handlerMappingAdapter = (RequestMappingHandlerAdapter) bean; + handlerMappingAdapter.getMessageConverters().add(0, applicationContext.getBean(SpaResourceConverter.class)); + } + return bean; + } + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + this.applicationContext = applicationContext; + } +} diff --git a/omod/src/main/resources/webModuleApplicationContext.xml b/omod/src/main/resources/webModuleApplicationContext.xml index 85e9529..1c474c0 100644 --- a/omod/src/main/resources/webModuleApplicationContext.xml +++ b/omod/src/main/resources/webModuleApplicationContext.xml @@ -18,10 +18,6 @@ - - - - - - + +