From b12d2ee145a254e0c9fef4f10295a4348a0c7368 Mon Sep 17 00:00:00 2001 From: Ian <52504170+ibacher@users.noreply.github.com> Date: Wed, 5 Jun 2024 13:07:13 -0400 Subject: [PATCH] O3-3347: Follow-up; don't use mvc:annotation-driven (#61) --- .../spa/spring/SpaBeanPostProcessor.java | 27 +++++++++++++++++++ .../resources/webModuleApplicationContext.xml | 8 ++---- 2 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 omod/src/main/java/org/openmrs/module/spa/spring/SpaBeanPostProcessor.java 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 @@ - - - - - - + +