Spring issue in FHIR

I’ve mentioned in some calls in the past some issues we’ve been having deploying the FHIR 2 module to some versions of OpenMRS. I’ve written up a ticket for it here with some of the details. I’ll be adding comments as I reconstruct the various things I’ve tried. If anyone has any insight into how to get Spring injection working in a Java Servlet, that would be very welcome!

cc: @dkayiwa

1 Like

Nothing strikes me off-hand. Since it is working in the SDK but not outside the SDK, I’d probably recommend getting set up outside of the SDK (eg. using a dockerized tomcat), and starting tomcat with the appropriate arguments to expose the Debug port, and then put some breakpoints in and see what is happening.

Thanks Mike! Yeah, I’ve been trying that with no real success (I keep getting lost deep in the bowels of Spring).

This should fix it in the standalone version of OpenMRS: https://github.com/openmrs/openmrs-standalone/commit/c2d3f8bf626a58878e5939f9214518561d4ce45b

Because Spring expects the javax.inject.Inject class to be loaded by the same class loader as the one which loaded the ‘Spring classes’, i would suggest that you change the fhir2 module’s javax.inject dependency to <scope>provided</scope>. Then put the javax.inject dependency in the OpenMRS core platform. For all environments where this problem does not happen, it means that they already had the ‘javax.inject.Inject’ class in the class path, which was then loaded by the class loader that loads Spring.

The other alternative would be to simply replace @Inject with @Autowired

@ibacher do you have any objections to this proposal?

No, not at all. I had reasons for favouring @Inject over @Autowired, but that can be undone. I’m more concerned with the continuing issues I was seeing after manually loading the Inject annotation, but maybe that will go away if we use @Autowired.

The downside of using @Inject is that the module would require at least maintenance versions of the openmrs platform that have got the javax.inject dependency. But with @Autowired, all will be well with what you already support.