Skip to content

Commit 437ffa6

Browse files
committed
Detect LoadTimeWeaver bean when declared through @bean method as well
Issue: SPR-10856
1 parent 21e4ac1 commit 437ffa6

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java

+7
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,13 @@ protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactor
679679
*/
680680
protected void invokeBeanFactoryPostProcessors(ConfigurableListableBeanFactory beanFactory) {
681681
PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(beanFactory, getBeanFactoryPostProcessors());
682+
683+
// Detect a LoadTimeWeaver and prepare for weaving, if found in the meantime
684+
// (e.g. through an @Bean method registered by ConfigurationClassPostProcessor)
685+
if (beanFactory.getTempClassLoader() == null && beanFactory.containsBean(LOAD_TIME_WEAVER_BEAN_NAME)) {
686+
beanFactory.addBeanPostProcessor(new LoadTimeWeaverAwareProcessor(beanFactory));
687+
beanFactory.setTempClassLoader(new ContextTypeMatchClassLoader(beanFactory.getBeanClassLoader()));
688+
}
682689
}
683690

684691
/**

0 commit comments

Comments
 (0)