You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using aspectj-maven-plugin to weave my sources and tests.
I have a spring-boot app, in which I want to use compile-time weaving of my code to manage JDBC transactions. Here is my portion of the maven file:
After the compilation phase, the integration test starts running, but it fails immediately with:
Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [my_package.microservice.MyManager] for bean with name 'myManager' defined in file [/my_project/service/target/test-classes/my_package/MyManager.class]: problem with class file or dependent class; nested exception is java.lang.ClassFormatError: Duplicate field name "ajc$tjp_0" with signature "Lorg.aspectj.lang.JoinPoint$StaticPart;" in class file my_package/MyManager
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1383)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:668)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:635)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1489)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:420)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:390)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:511)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:503)
at org.springframework.boot.context.TypeExcludeFilter.match(TypeExcludeFilter.java:65)
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.isCandidateComponent(ClassPathScanningCandidateComponentProvider.java:492)
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.scanCandidateComponents(ClassPathScanningCandidateComponentProvider.java:431)
... 51 common frames omitted
How do I solve this issue?
The text was updated successfully, but these errors were encountered:
the same thing happened to me, with a very similar AspectJ weaving scheme (i.e weaving already compiled classes produced in the Maven build during the compilation phase).
In my case, the reason was that the classes to be woven (located in the weaveDirectory directory ) were woven twice:
the first time, when executing the goal <compile>
the second time, when executing the goal <test-compile>
With this weaving scheme (as opposed to specifying classes to be woven by their source files with <sources>/<testSources> ... <include>/<exclude> directives), I found the XnotReweavable parameter convenient.
Adding:
<XnotReweavable>true</XnotReweavable>
to the <configuration> element did the trick: even if the same weaveDirectory is used both for <compile> and <test-compile> goals, classes are not rewoven, and so the Duplicate field name "ajc$tjp_0" exception raised when executing the unit tests disappears
Another (cleaner, but not tested yet) solution would be to have two distinct <weaveDirectory> configurations for test and compile goals.
For the <goal>test-compile</goal>, one could define the tests compilation target directory ${project.build.directory}/test-classes as the <weaveDirectory>
I am using aspectj-maven-plugin to weave my sources and tests.
I have a spring-boot app, in which I want to use compile-time weaving of my code to manage JDBC transactions. Here is my portion of the maven file:
After the compilation phase, the integration test starts running, but it fails immediately with:
How do I solve this issue?
The text was updated successfully, but these errors were encountered: