Skip to content

LoadTimeWeaver no longer weaves bean classes annotated with @Component #26199

Closed
@emillundstrm

Description

@emillundstrm

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:

<context:component-scan base-package="com.acme.spring"/>
<context:load-time-weaver aspectj-weaving="on" />

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:

[WebAppClassLoader@58437801] debug weaving 'com.acme.spring.TestBean'
[WebAppClassLoader@58437801] weaveinfo Join point 'method-execution(void com.acme.spring.TestBean.run())' in Type 'com.acme.spring.TestBean' (TestBean.java:11) advised by around advice from 'org.springframework.transaction.aspectj.AnnotationTransactionAspect' (AbstractTransactionAspect.aj:66)
[WebAppClassLoader@58437801] debug generating class 'com.acme.spring.TestBean$AjcClosure1'

A workaround is using aspectjweaver.jar as -javaagent, but that is inconvenient if you don't control the JVM flags.

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchestype: regressionA bug that is also a regression

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions