admin管理员组

文章数量:1352849

I have a big application written in Tapestry using @Transactional annotation from Spring to manage transactions and Hibernate sessions. At the moment I'm in a process of upgrading dependencies, including Spring.

The problem is that @Transactional aspect used to be before/after, but has been changed to around and this collides with PlasticClassLoader. The aspect is weaved using post-compile weaving. Whenever any local method (private or public) is called, it fails with

java.lang.ClassCastException: class XYZ cannot be cast to class XYZ (XYZ is in unnamed module of loader .apache.tapestry5.internal.plastic.PlasticClassLoader @162b4f91; XYZ is in unnamed module of loader 'app')

For example I have an onSuccessFrom... method and this method cannot call another method from the same class which is annotated with @Transactional, because it fails like above.

Any idea how to fix it?

I have a big application written in Tapestry using @Transactional annotation from Spring to manage transactions and Hibernate sessions. At the moment I'm in a process of upgrading dependencies, including Spring.

The problem is that @Transactional aspect used to be before/after, but has been changed to around and this collides with PlasticClassLoader. The aspect is weaved using post-compile weaving. Whenever any local method (private or public) is called, it fails with

java.lang.ClassCastException: class XYZ cannot be cast to class XYZ (XYZ is in unnamed module of loader .apache.tapestry5.internal.plastic.PlasticClassLoader @162b4f91; XYZ is in unnamed module of loader 'app')

For example I have an onSuccessFrom... method and this method cannot call another method from the same class which is annotated with @Transactional, because it fails like above.

Any idea how to fix it?

Share Improve this question edited Apr 1 at 8:41 M. Deinum 125k22 gold badges233 silver badges249 bronze badges asked Apr 1 at 8:00 bedneebednee 12 bronze badges 12
  • If post-compile weaving is used the error doesn't make sense. As post-compile would modify the bytecode before anything else. This is a runtime exception indicating that proxies are also created (or that other things are going on). Add your configuration to the question and the versions of the frameworks in use. – M. Deinum Commented Apr 1 at 8:40
  • In addition it was an around aspect since the beginning and not an before/after aspect . So not sure where you get that information from but that is plain wrong, as it would only work with an around aspect. – M. Deinum Commented Apr 1 at 8:57
  • Well, previous Spring version was quite old, so old that it was indeed before/after. Anyhow, the problem seems to be with the way AspectJ with Java 21 weaves the classes. It now generates closure classes rather than inlining the code and the closure class has a different loader. Version setup is Java 21, Tapestry 5.8.7, Spring 5.3.39 (only spring-context, tx, aspects and orm), AspectJ 1.9.23 with io.freefair.aspectj.post-compile-weaving. – bednee Commented Apr 1 at 9:11
  • You are upgrading from what to what. Also Spring 5.3 might not even support Java 21. Please add that information in your question and not as a comment. – M. Deinum Commented Apr 1 at 9:43
  • Java 11 to 21, Spring 4.3.15 to 5.3 (cannot use 6 because of Jakarta). The weaved code before had AnnotationTransactionAspect.aspectOf().ajc$before$_springframework_transaction_aspectj_AbstractTransactionAspect$1$2a73e96c(this, ajc$tjp_1); at the begining of @Transactional method, while now it's ((AbstractTransactionAspect)var10000).ajc$around$_springframework_transaction_aspectj_AbstractTransactionAspect$1$2a73e96c(this, new ApplicationPropertiesImpl$AjcClosure1(var6), ajc$tjp_0); – bednee Commented Apr 1 at 9:57
 |  Show 7 more comments

1 Answer 1

Reset to default 0

Too many issues can exist, with unnamed module, since I am not able to comment due to point issues, I have found the answer check the answers on the link & fix your the issue.

https://stackoverflow/a/57753612/16897849

本文标签: javaTapestry bean with Around aspect class loading problemStack Overflow