Troubles when using AspectJ LTW with core module's OrmXmlAwareClassLoader

Hi,
we are considering using aspects for domain entity objects to ensure some constraints and check some conditions using AspectJ LTW since they are not beans.

Let’s say to prohibit calls for annotated methods in web block and that works well, since web block uses ParallelWebappClassLoader which supports transformations. Moreover with Spring @Configurable annotations there is an easier way to inject beans without boring AppBeans (actually not sure whether it’s a good idea or not).

Some troubles happen when <context:load-time-weaver> present in core block. Because of OrmXmlAwareClassLoader a bean implementing DefaultContextLoadTimeWeaver fails to initialize, using spring-instrumentation doesn’t help as well.

Any ideas about using aspects in general and this particular trouble?
Thanks in advance.

Ilia.

Hi,

Could you provide the sample project?
I think overriding DefaultContextLoadTimeWeaver and using parent class loader instead of OrmXmlAwareClassLoader should help.

Hi,
thank you for a reply.
Could you elaborate what should be overriden in the weaver?
I prepared a sample project, please see https://github.com/wrover/cuba-aop

Hi,

In that case you should define exact LoadTimeWeaver by set weaver-class attribute for <context:load-time-weaver> at spring.xml. With Tomcat it should be like:
<context:load-time-weaver aspectj-weaving="on" weaver-class ="org.springframework.instrument.classloading.tomcat.TomcatLoadTimeWeaver"/>.

Hi,
using TomcatLoadTimeWeaver the error about OrmXmlAwareClassLoader has gone, but no weaving takes place going by logs and behavior. Actually we abandoned that idea for its complications.

Regards,
Ilya.

Hi,
In that sample project to make weaving possible you should annotate by annotation @Model elements of core-module beans or run annotated code inside of these beans.

Regards,
Sergey.

For beans it would be easier to just use Spring AOP. The idea was about weaving aspects into non managed by Spring objects like entities.

Regards,
Ilya.