Hi,
I am working on this issue https://issues.openmrs.org/browse/TRUNK-4663. as part of this issue, I am trying to convert applicationContext-service.xml to java config. During this conversion i came across this circular dependency issue between openmrsEventListeners and adminServiceTarget beans, they works fine with xml configuration and throws “globalPropertyListener threw exception; nested exception is java.lang.StackOverflowError” when i run with translated spring java config. please find both xml and java bean configurations below. The problem is in the adminServiceTarget which is being referenced in openmrsEventListeners and if you look at adminServiceTarget bean definition, it intern requires openmrsEventListeners.
Existing xml config
<bean id="adminServiceTarget" class="org.openmrs.api.impl.AdministrationServiceImpl">
<property name="administrationDAO"><ref bean="adminDAO"/></property>
<property name="eventListeners"><ref bean="openmrsEventListeners"/></property>
<property name="globalLocaleList"><ref bean="globalLocaleList"/></property>
<property name="implementationIdHttpClient"><ref bean="implementationIdHttpClient"/></property>
</bean>
<bean id="openmrsEventListeners" class="org.openmrs.api.EventListeners" depends-on="clearOpenmrsEventListeners">
<property name="globalPropertyListeners">
<list value-type="org.openmrs.api.GlobalPropertyListener">
<bean class="org.openmrs.util.LocaleUtility" />
<bean class="org.openmrs.util.LocationUtility" />
<bean class="org.openmrs.api.impl.PersonNameGlobalPropertyListener" />
<ref bean="globalLocaleList" />
<ref bean="adminServiceTarget" />
<ref bean="orderServiceTarget" />
</list>
</property>
</bean>
After translating the above xml config to Java config I have the below code
@Bean
@DependsOn("clearOpenmrsEventListeners")
public EventListeners openmrsEventListeners() throws IOException {
EventListeners eventListeners = clearOpenmrsEventListeners();
List<GlobalPropertyListener> globalPropertyListeners = new ArrayList<GlobalPropertyListener>();
globalPropertyListeners.add(localUtility());
globalPropertyListeners.add(locationUtility());
globalPropertyListeners.add(personNameGlobalPropertyListener());
globalPropertyListeners.add(globalLocaleList());
//Commented to resolve the cyclic dependency
globalPropertyListeners.add(adminServiceTarget());
globalPropertyListeners.add(orderServiceTarget());
eventListeners.setGlobalPropertyListeners(globalPropertyListener());
return eventListeners;
}
@Bean
public AdministrationServiceImpl adminServiceTarget() throws IOException {
AdministrationServiceImpl administrationServiceImpl = new AdministrationServiceImpl();
administrationServiceImpl.setAdministrationDAO(adminDAO());
administrationServiceImpl.setEventListeners(openmrsEventListeners());
administrationServiceImpl.setGlobalLocaleList(globalLocaleList());
administrationServiceImpl.setImplementationIdHttpClient(implementationIdHttpClient());
return administrationServiceImpl;
}