[jboss-user] [Snowdrop] - Spring Load-Time Weaving in JBoss AS 6: Usage Notes

Marius Bogoevici do-not-reply at jboss.com
Tue Feb 8 15:49:51 EST 2011

Marius Bogoevici [http://community.jboss.org/people/marius.bogoevici] modified the document:

"Spring Load-Time Weaving in JBoss AS 6: Usage Notes"

To view the document, visit: http://community.jboss.org/docs/DOC-16458

Load-time weaving for AspectJ is a powerful feature of the Spring Framework and JBoss is one of the servers which Spring is capable of detecting automatically and for which it provides an out-of-the box LoadTimeWeaver implementation. 

This means, that when running in JBoss AS 5 and later (including JBoss AS 6) the application context definition needs to include only the default namespace configuration option:


As a result, the application context definition is fully portable and can be used for deploying in other environments.

When running in JBoss AS 6 there is one thing that you need to pay attention to: Spring's load-time weaving feature is based upon the fundamental yet not explicitly formulated assumption that the woven classes will be loaded after the application context has been started.

While this may be true in certain cases, it is still an assumption that is not backed by a standard. Wherever it is not valid, this assumption becomes a limitation and you will notice that the target classes will not be advised, although a Transformer has been registered with the classloader. What happens really is that the required transformations are not performed on the target classes, because they are already loaded.

In the particular case of JBoss AS 6, this can happen due to the annotation scanning performed by the application server. Starting with Java EE 5, annotations have been increasingly adopted means of specifying component metadata, reducing or even elliminating the need of deployment descriptors. This has simplified the task of developers, but at the same time, the deployment process has become more expensive - instead of reading metadata from a well-known location, containers have to scan and extract it from the application classes.

One of the most expensive parts of this process is reading class annotations. For solving this problem, JBoss will scan and index the application classes upfront once, leaving the individual deployers the task of interpreting them.

In JBoss AS 6, class scanning can use either Java Introspection or Javassist for reading class data. The former is more performant and therefore enabled by default, but will also load the application classes while reading their information - Javassist will read the information directly from the bytecode.

So, out of the box, with Introspection enabled, Spring applications that use load-time weaving will see their application classes unadvised. Fortunately, being aware of how load-time weaving actually works and what the assumptions (or limitations) are, you can either:

1. Reduce the scope of annotation scanning by providing a jboss-scanning.xml configuration file in your deployment see [1] and [2] for more details. While this is adding a JBoss-specific metadata to your deployment, the application remains portable as other environments will effectively ignore it - and, once again, the goal is to align the expectations of the framework (no classes will be pre-loaded) with the behaviour of the container (will load classes by default but will back off when told not to do so). This option has the advantage that works with the default JBoss AS6 configuration and can be enabled per-deployment. However, please note that annotation scanning is necessary for Java EE components, so you need to be careful what you actually exclude.
2. Switch scanning from Introspection to Javassist. This option will be available only in JBoss AS 6.1 and later (and not in JBoss AS 6.0.0.Final). In order to do so, you need to launch the AS with a specific startup option like this:

 ./run.sh -Dorg.jboss.reflect.spi.TypeInfoFactory=org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactory

Please note that this will enable Javassist for the entire application server. This option is not available in JBoss AS 6.0.0.Final.


[1]  http://java.dzone.com/articles/jboss-microcontainer-scanning http://java.dzone.com/articles/jboss-microcontainer-scanning
[2]  http://community.jboss.org/docs/DOC-13178 http://community.jboss.org/wiki/JBoss5custommetadatafiles

Comment by going to Community

Create a new document in Snowdrop at Community
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20110208/88d408d1/attachment-0001.html 

More information about the jboss-user mailing list