Marius Bogoevici [
http://community.jboss.org/people/marius.bogoevici] created the
document:
"Spring Load-Time Weaving in JBoss AS 6: A Few 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:
<context:load-time-weaver/>
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 loadaed.
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, the 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 use 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. 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 (available in JBoss AS 6.1). 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.
--------------------------------------------------------------
Comment by going to Community
[
http://community.jboss.org/docs/DOC-16458]
Create a new document in Snowdrop at Community
[
http://community.jboss.org/choose-container!input.jspa?contentType=102&am...]