Autowiring module defined beans in the Openmrs context returns null

Hi all,

This is a little annoying :rage:

I defined an MPDClient bean here but looks like Autowiring it here returns null yet it works in Test classes that extend BaseModuleContextSensitiveTest eg this. Could I be missing something here?

cc: @mksd , @dkayiwa , @ssmusoke

@samuel34, if MPDClientClassBuilder is not spring-managed, then I don’t think you will be able to wire beans into it . Also, not sure if this is also an issue, but using both @Component and defining the bean within your applicationcontext.xml file will result in two instances of the same bean in the context, I believe.

Mike

@samuel34 because there is no spring application context in your test, BaseModuleContextSensitiveTest has one because it extends AbstractJUnit4SpringContextTests which sets up and provides the application context.

Thanks @wyclif and @mseaton you saved lots of my time :slight_smile:

What’s the best trending practice in the sense of wiring beans , Annotation vs moduleApplicationContext.xml ?

Annotations could be probably better but a debate was loosely raised on this. It was realized that they slow down the system as compared to moduleApplicationContext.xml .

cc: @raff

1 Like