New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@EnableLoadTimeWeaving does not work for spring beans annotated by @Component, @Configuration, etc. #26851
Comments
This appears to be a duplicate of #26199. I am therefore closing this issue. If you find that the issue still exists after upgrading to Spring Framework 5.3.5 or 5.3.6, please post back here as a comment, and we will investigate further. |
After I upgraded Spring to the latest version(5.3.6), this problem still exists. Although the bean class is not loaded earlier in the I found through debug mode that in the process of instantiating private String[] doGetBeanNamesForType(ResolvableType type, boolean includeNonSingletons, boolean allowEagerInit) {
List<String> result = new ArrayList<>();
// Check all bean definitions.
for (String beanName : this.beanDefinitionNames) {
// Only consider bean as eligible if the bean name is not defined as alias for some other bean.
if (!isAlias(beanName)) {
try {
RootBeanDefinition mbd = getMergedLocalBeanDefinition(beanName);
// Only check bean definition if it is complete.
if (!mbd.isAbstract() && (allowEagerInit ||
(mbd.hasBeanClass() || !mbd.isLazyInit() || isAllowEagerClassLoading()) &&
!requiresEagerInitForType(mbd.getFactoryBeanName()))) {
//**************************This line of code will cause other bean classes to be loaded*******************
boolean isFactoryBean = isFactoryBean(beanName, mbd); I think this may be the cause of the load time weaver not working. Hope to get your reply , thank you very much. |
Thanks for looking into it and providing feedback. We have reopened this issue and will investigate the cause. |
Did it work for your application using If so, which version? |
Sorry, I haven't tried any version before 5.3.4 so far |
OK. Thanks for the feedback. I was asking in order to confirm if this is a "regression", but since you don't know that we might discover that this scenario never worked. |
@sbrannen I think there was a problem in this commit. Is there a rationale for that or is it a bug? we have a change of behavior because of this. This verification was missed I think. |
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed. |
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue. |
@sbrannen The issue is not resolved in Spring Framework 5.3.21. It can be reproduced by cloning this repo, checking out branch |
Affects: Spring Framework 5.3.4
When I use the
@EnableLoadTimeWeaving
annotation, beans will not be woven, but using XML configuration<context:load-time-weaver/>
can be successfully woven.Here's a snippet that use
@EnableLoadTimeWeaving
annotation:aop.xml
the aspect
In this simple case, the
EntitlementCalculationService
object that was successfully woven will print the execution time . As mentioned before,service2
prints the execution time,service1
does not, proving that it was not successfully woven.When switching to the XML configuration method, both
service1
andservice2
can be successfully woven, and they can both print the execution time.When using Java configuration, the
AspectJWeavingEnabler.enableAspectJWeaving
method will not be called until Spring loads the bean classes, which seems to be the reason why@EnableLoadTimeWeaving
does not take effect.The text was updated successfully, but these errors were encountered: