Skip to content

Commit

Permalink
O3-3347: Follow-up; don't use mvc:annotation-driven (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibacher authored Jun 5, 2024
1 parent 76dff5a commit b12d2ee
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
}
8 changes: 2 additions & 6 deletions omod/src/main/resources/webModuleApplicationContext.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
<context:annotation-config />
<bean id="spaResourceLoader" class="org.openmrs.module.spa.SpaResourceLoader" />
<bean class="org.openmrs.module.spa.SpaController" />

<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.openmrs.module.spa.SpaResourceConverter" />
</mvc:message-converters>
</mvc:annotation-driven>
<bean class="org.openmrs.module.spa.SpaResourceConverter" />
<bean class="org.openmrs.module.spa.spring.SpaBeanPostProcessor" />
</beans>

0 comments on commit b12d2ee

Please sign in to comment.