We, the Snowdrop Dev team, have been trying to speed up Spring's Component Scanning.
Typically, Spring Applications make use of the context namespace to add beans to the Spring Container, example: <context:component-scan base-package="foo.bar"/>. In order to identify the beans it needs to initialize, Spring looks through the package and scans for @Component and its extensions. For packages with large number of Components, this process is fairly slow.
The specific steps are as follows:
After bootstrapping, the set of application components and service that need to be created are identified. AbstractbeanDefinitionReader will read resource definitions. DefaultListableBeanFactorywill be used as default bean factory based on bean definition objects.XmlBeanDefinitionReader.loadBeanDefinitions() load bean definitions from the specified XML file in which the BeanDefinitionParser will identify the context namespaces and parses the applicationContext xml. The resources are identified by the implementation of ResourcePatternResolver:, ie PathMatchingResourcePatternResolver in which the location patterns are found like an ant-style. Internally it uses ClassLoader.getResources(String name) method which returns an Enumeration containing URLs representing classpath resources. Then the ComponentScanBeanDefinitionParser will parse through the context definition nodes.
It is this last step that we want to speed up and to do so we are attempting to leverage JBoss' Jandex module.
At the start of deployment in JBoss, the Jandex module scans the classes and creates an Annotation Index. We would like to be able to utilize this Index to skip the scanning step and just initialize the pre-identified components.
Component-Scan within snowdrop's jboss namespace - https://github.com/snowdrop/snowdrop/tree/CustomBeanScanner:
One option is to add our custom component scanner to snowdrop's namespace. So instead of <context:component-scan base-package="foo.bar"/>, the user would use: <jboss:component-scan base-package="foo.bar"/>.
While this has the downside that the user has to change their application to make use of the feature, it forces the user to make a conscious decision.
What do you think of this feature and of how it couples a Spring app with JBoss? Is the intentional coupling worth the speed increase?
Thanks in advance for the feedback,
Tejas M. on behalf of the Snowdrop Team