<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    Spring Load-Time Weaving in JBoss AS 6: Usage Notes
</h3>
<span style="margin-bottom: 10px;">
    modified by <a href="http://community.jboss.org/people/marius.bogoevici">Marius Bogoevici</a> in <i>Snowdrop</i> - <a href="http://community.jboss.org/docs/DOC-16458">View the full document</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>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. </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>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:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code jive-xml"><span class="jive-xml-tag">&lt;context:load-time-weaver/&gt;</span></code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>As a result, the application context definition is fully portable and can be used for deploying in other environments.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>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.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>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.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>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.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>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.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>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.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>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:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><ol><li>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.</li><li>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:</li></ol><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; </p><pre class="jive-pre"><code class="jive-code"> ./run.sh -Dorg.jboss.reflect.spi.TypeInfoFactory=org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactory
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="padding-left: 30px;">Please note that this will enable Javassist for the entire application server. This option is not available in JBoss AS 6.0.0.Final.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Links:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>[1] <a class="jive-link-external-small" href="http://java.dzone.com/articles/jboss-microcontainer-scanning">http://java.dzone.com/articles/jboss-microcontainer-scanning</a></p><p>[2] <a class="" href="http://community.jboss.org/docs/DOC-13178">http://community.jboss.org/wiki/JBoss5custommetadatafiles</a></p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Comment by <a href="http://community.jboss.org/docs/DOC-16458">going to Community</a></p>

        <p style="margin: 0;">Create a new document in Snowdrop at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=102&containerType=14&container=2082">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>