Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jairovsky/29c9cedb2b4b03cb20ed25dd51f39a77 to your computer and use it in GitHub Desktop.
Save jairovsky/29c9cedb2b4b03cb20ed25dd51f39a77 to your computer and use it in GitHub Desktop.
Lazy loading for spring integration/component tests
/**
* Enables lazy initialization of beans in tests, which means that
* only the beans you're actually using in a test will be initialized/instantiated for you.
*
* The main advantage of this approach is that it removes the need to configure
* properties for beans that you are not even using.
*/
@TestComponent
class LazyInitializationBeanFactoryPostProcessor : BeanFactoryPostProcessor {
override fun postProcessBeanFactory(beanFactory: ConfigurableListableBeanFactory) {
for (name in beanFactory.beanDefinitionNames) {
beanFactory.getBeanDefinition(name).isLazyInit = true
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment