Inquires on how to handle controllers with no specified service references while contructing beans

hello there i am currently working on this tickect; [TRUNK-6131] - OpenMRS Issues where we are suppose to replace @component-scan with @import in order to speed up startup time. with annotation could be easy for but that challenge comes with dealing with xml cofigurations, <import/> deals ony with xmls not classes that could only mean i should make beans of various config classes that is to say controller-config.xml and so on

i am faced with a challenge on how to ideal with a controller that has no specific service class for example org.openmrs.web.controller.PseudoStaticContentController in the core

the alternative is to to use both component-scan and import tag which i think may yield better result. may question is if am to created i bean of such a class how should i treat its properties or write them

@dkayiwa @ibacher @ruhanga

So the idea here would be that after the implementation Spring’s stereotype annotations (like @Controller, etc.) are only honored if they are referenced directly in a Java config or an XML config. This adds extra steps to implementations, but it’s the key to getting the performance boost the ticket is looking for.

Way too deep of a technical dive:

Every time Spring encounters a @ComponentScan annotation, it spawns a new ComponentScanAnnotationParser; similarly, each time it encounters a <component-scan /> record, it spawns a ComponentScanBeanDefinitionParser. Each instance of either of these classes creates a ClassPathBeanDefinitionScanner, and this, in turn ultimately creates a PathMatchingResourcePatternResolver which will independently load all of the available resources from the classpath that start with the specified package.

Now the underlying reason this becomes an issue is because the ClassLoader in place is the OpenmrsClassLoader, which in turn defers to the ModuleClassLoader, which is… not very efficient. It’s probably fine to do this a few times, but because with, say 40ish modules you might have 40ish component scans, that adds up to a large amount of time.

4 Likes