huge delay on applicationContext refresh with listeners

refreshing application context after all modules are started in realtime not unit test environment takes more than an hour to create messageSource bean when resolving reference to another bean.

This happens when i add/install a module that adds listener bean(s) and only when i start OpenMRS not when i install the module after starting OpenMRS from the module admin page

looks like the delay happens here.

taking a further look to see what causes this. In-case one has experienced this before or would highly and quickly suspect the cause, here is the application context file: and a sample listener at: a long wait passes on after atleast an hour such as:

I noticed that UserServiceImpl has the List of PrivilegeListeners @Autowired into it. Auto-wiring into services has been the source of big performance issues in the past. I would not be surprised if this is your issue.

Can you try modifying core to load privilege listeners in another way that does not use the @Autowired annotation, and see if that dramatically improves things?


1 Like

good point, the alternative approach is worth considering as well, i just looked through and most seem questionable to me still.

If this is the issue, I suspect that it may actually be okay to use constructor autowiring (but not field autowiring). If you have the inclination to do that experiment and report back, it would be very helpful to know whether that’s the case.

am already attempting out constructor injection to see if it helps

@k.joseph recall I did comment on the PR for adding login/logout listeners to use Context.getRegisteredComponents() to get the list of registered listeners rather than auto wiring them because it has the benefit of addressing the issue @mseaton is trying to point out.

1 Like

solves the issue and improves startup, i have done the change for privilegeListeners as well.

Can you comment on whether doing constructor injection also solved the problem, or did not solve the problem? (Or, didn’t fully test and can’t comment?)

It would be nice to test but my guess is that constructor injection might not solve it since it also happens at startup.

For anyone who may have the same query, constructor injection reduced my bootup time from 15 minutes to 3 minutes.