Created
July 19, 2019 21:11
-
-
Save jairovsky/29c9cedb2b4b03cb20ed25dd51f39a77 to your computer and use it in GitHub Desktop.
Lazy loading for spring integration/component tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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