We have two modules in our project
app-ui is a portlet
project follows spring based implementation and
app-services has restful and soap
services follows Java EE 6 based implementation. We want to enable security, logging and
exception handling aspects through out the modules.
We face the following problems:<ol><li>Spring aop works well only in app-ui. In app-services side we tried using Load-Time Weaving and spring-bridging but did not succeed, it works successfully only if beans.xml(Java EE 6) is not present in the project.</li> <li>We tried Java EE global interceptors (placing in ejb-jar.xml), which works only for EJBs. Hence it wont work in app-ui.</li> </ol>
Is there a way to develop aspects common to app-ui and app-services?Answer1:
Using AspectJ directly and not the spring specific support for it it should work OK, this allows to develop aspects that work both in Spring and Java EE.
There are three ways to weave the AspectJ aspects into the code:<ul><li>
compile time weaving, meaning we need to have the code</li> <li>
<a href="http://www.eclipse.org/aspectj/doc/next/devguide/bytecode-concepts.html" rel="nofollow">byte code weaving</a> can be used for third party jars for which no code is available</li> <li>
<a href="http://www.eclipse.org/aspectj/doc/next/devguide/ltw-packaging.html" rel="nofollow">load time weaving</a> (not the spring specific support) can be used to weave the aspects at class loading time, this can be more invasive as it requires a JVM wide agent, and access to the server startup script.</li> </ul>
The <a href="http://docs.spring.io/spring/docs/3.0.0.RC2/reference/html/ch07s08.html#aop-aj-ltw" rel="nofollow">spring support for LTW</a> allows to use LTW in a more convenient way but it only works for spring applications, unlike the LTW general mechanism above.
So if using LTW directly is too cumbersome, byte code weaving and compile time weaving are still valid options, although with impact on the build process.