JBoss.org Community Documentation
To deploy an AOP application in JBoss you need to package it. AOP is packaged similarly
to SARs(MBeans). You can either deploy an XML file directly in the deploy/ directory
with the signature *-aop.xml along with your package (this is how the base-aop.xml,
included in the
jboss-aop.deployer
file works) or you can include it in
the jar file containing your classes. If you include your xml file in your jar,
it must have the file extension .aop and a jboss-aop.xml file must be contained
in a META-INF directory, i.e.
META-INF/jboss-aop.xml
.
Note that in JBoss 5, you MUST specify the schema used, otherwise your information will not be
parsed correctly. You do this by adding the xmlns="urn:jboss:aop-beans:1:0
attribute to the root aop
element, as shown here:
<aop xmlns="urn:jboss:aop-beans:1.0"> </aop>
If you want to create anything more than a non-trivial example, using the .aop jar
files, you can make any top-level deployment contain a .aop file containing the xml
binding configuration. That is you can have a .aop file in an .ear file, or a .aop
file in a war file etc. The bindings specified in the
META-INF/jboss-aop.xml
file contained in the .aop file will affect all the classes in the whole war!
To pick up a .aop file in an .ear file, it must be listed in the
.ear/META-INF/application.xml
as a java module, e.g.:
<?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE application PUBLIC '-//Sun Microsystems, Inc.//DTD J2EE Application 1.2//EN' 'http://java.sun.com/j2ee/dtds/application_1_2.dtd'> <application> <display-name>AOP in JBoss example</display-name> <module> <java>example.aop</java> </module> <module> <ejb>aopexampleejb.jar</ejb> </module> <module> <web> <web-uri>aopexample.war</web-uri> <context-root>/aopexample</context-root> </web> </module> </application>
Note that in newer versions of JBoss (>= 4.0.5), the contents of the .ear file are deployed in the order they are listed in the application.xml. When using loadtime weaving the bindings listed in the example.aop file must be deployed before the classes being advised are deployed, so that the bindings exist in the system before the ejb, servlet etc. classes are loaded. This is acheived by listing the .aop file at the start of the application.xml. Older versions of JBoss did not have this issue since the contained .aop files were deployed before anything else, and this still holds true for other types of archives such as .sar and .war files.