-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
LoadTimeWeaver no longer weaves bean classes annotated with @Component #26199
Comments
Ha, came here by chance. Isn't it the case that jetty is one of the servlet containers that doesn't contain a load time weaver and therefore requires a java agent? |
If this were the case, there'd be an error similar to:
But this is not the case. There is no error, because Jetty 9.x provides addTransformer. And it wouldn't explain why it works from XML, but not from annotations. |
I believe the difference from beans defined by if ((configClassAttr != null || methodMetadata != null) && beanDef instanceof AbstractBeanDefinition) {
// Configuration class (full or lite) or a configuration-derived @Bean method
// -> resolve bean class at this point...
AbstractBeanDefinition abd = (AbstractBeanDefinition) beanDef;
if (!abd.hasBeanClass()) {
try {
abd.resolveBeanClass(this.beanClassLoader);
}
catch (Throwable ex) {
throw new IllegalStateException(
"Cannot load configuration class: " + beanDef.getBeanClassName(), ex);
}
}
} The XML bean has null |
Hey guys. I stumbled across this searching for a solution to my problem which I have reported today on stackoverflow. Reading the issue description this seems to be the same issue I have. Same situation: upgrade from 4.3.14 to 5.3.3 under Tomcat 9. Only few classes are being woven. But until now I was not able to figure out which one did work. I can confirm the workaround with the aspectjweaver agent is working, but not applicable for my use case. Has there been any progress made on this or is there another workaround than the one with the javaagent? |
AFAIK, this was the workaround, from the days of the application servers, which would deploy multiple applications and you could not install a JVM agent that would affect all, while in the modern days, the agent is the recommended way. |
For me this is quite a problem as the |
@emillundstrm, thanks for sharing your analysis.
If that's the case, this might be a regression caused by the changes in 40c6213, stemming from the fact that a @jhoeller, thoughts? |
Ran into this issue yesterday. We upgraded to 5.2.12 recently and noticed yesterday that our app would stop working after a while in our test environment. Threads were waiting on database connections from the connection pool. It turns out that our |
We will be working on a fix for Spring Framework 5.3.5 and potentially backporting to 5.2.14.
Well, I haven't tried this out, but based on my initial analysis of the regression, it appears that annotating your class with @goetzseb, please try annotating some of your component scanned classes with |
I have confirmed that this is a regression introduced in Spring Framework 5.2.0.
Using I have also confirmed that the mere presence or meta-presence of |
Since Spring Framework 5.2, the LoadTimeWeaver no longer weaves bean classes annotated with @component. This is a regression caused by the changes in 40c6213, stemming from the fact that any class annotated or meta-annotated with @component is considered to be a candidate configuration class in 'configuration lite' mode (i.e., a class without the @configuration annotation and without any @bean methods) and therefore now has its class eagerly loaded. This results in the class being loaded before the LoadTimeWeaver has a chance to weave it. This commit fixes this regression by explicitly avoiding eager class loading for any 'lite' @configuration or @component class without @bean methods. Closes spring-projectsgh-26199
This regression has been fixed in Feel free to try it out in the upcoming snapshots for Spring Framework 5.3.5 and 5.2.14, and please report back on whether it works for you. |
Great to hear and thank you very much! |
Since Spring Framework 5.2, the LoadTimeWeaver no longer weaves bean classes annotated with @component. This is a regression caused by the changes in 40c6213, stemming from the fact that any class annotated or meta-annotated with @component is considered to be a candidate configuration class in 'configuration lite' mode (i.e., a class without the @configuration annotation and without any @bean methods) and therefore now has its class eagerly loaded. This results in the class being loaded before the LoadTimeWeaver has a chance to weave it. This commit fixes this regression by explicitly avoiding eager class loading for any 'lite' @configuration or @component class without @bean methods. Closes spring-projectsgh-26199
@sbrannen Doesn't work for me in either versions. It can be reproduced by cloning this repo, checking out branch |
We are using a combination of XML and Annotation configuration in a Spring web application. After upgrading to Spring 5.3.1 (from Spring 4), some classes are not processed by the AspectJ Load Time Weaver. In our XML configuration we have:
But AspectJ weaving only works for a subset of all classes. In particular, it does not work for classes found by component-scan. If the same bean is declared in XML, it works as expected.
We have managed to condense it into a small sample application:
https://github.com/emillundstrm/springaspectjtest
Running
mvn jetty:run
you will find that there is no message about com.acme.spring.TestBean being woven.However, if you remove the
@Component
annotation from TestBean and instead declare it in ApplicationContext.xml, this is logged:A workaround is using aspectjweaver.jar as
-javaagent
, but that is inconvenient if you don't control the JVM flags.The text was updated successfully, but these errors were encountered: