Table of Contents
Most configuration is accomplished by importing the custom config namespace into your Spring bean definition file, and then using it to define the appropriate elements. You can find probably find an example in the section called “Configuration Examples” and then customize it to suit your needs using the schema reference in the section called “XML Schema Documentation for http://www.mantis-tgi.com/schema/bt/1.1”.
Unless otherwise specified, all schema elements support the "id" attribute for injection into other Spring beans, in addition to those listed here.
The simplest example in Chapter 1, Quick Start should suit most applications. Here are some common (and less common) customizations:
Example 3.1. Store performance logs in the Tomcat logs directory
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bt="http://www.mantis-tgi.com/schema/bt/1.1" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.mantis-tgi.com/schema/bt http://www.mantis-tgi.com/schema/bt/mtgi-bt-1.1.xsd"> <bt:manager application="myapp"> <bt:xml-persister file="${catalina.home}/logs/myapp-beet.xml"/></bt:manager>
Example 3.2. Use a custom SessionContext implementation to specify user IDs
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bt="http://www.mantis-tgi.com/schema/bt/1.1" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.mantis-tgi.com/schema/bt http://www.mantis-tgi.com/schema/bt/mtgi-bt-1.1.xsd"> <bt:manager application="myapp"> <bt:session-context class="com.me.MySessionContextImpl"/> </bt:manager>
![]() | This class must implement com.mtgi.analytics.SessionContext. The <bt:session-context> element is otherwise a normal Spring bean definition, and may include nested property elements and so on. |
Example 3.3. Send tracking data for different packages to different log files
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bt="http://www.mantis-tgi.com/schema/bt/1.1" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.mantis-tgi.com/schema/bt http://www.mantis-tgi.com/schema/bt/mtgi-bt-1.1.xsd"> <bt:config> <bt:manager id="loggerA" application="myapp" track-method-expression="execution(* com.mtgi.package_a..*Tracked(..))"> <bt:xml-persister file="log-a.xml"/> </bt:manager> <bt:manager id="loggerB" application="myapp" track-method-expression="execution(* com.mtgi.package_b..*Tracked(..))"> <bt:xml-persister file="log-b.xml"/>
</bt:manager> </bt:config>
![]() | When specifying multiple <bt:manager> instances in a single application, you must provide unique IDs for each. |
![]() | An important consequence of having multiple managers in a single application is that each will define a private thread pool for persistence operations. If you want to have them all share a thread pool (which is not a bad idea), use the <bt:manager> attribute "task-executor". |
Example 3.4. Integrate beet with other AOP advice
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:bt="http://www.mantis-tgi.com/schema/bt/1.1" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.mantis-tgi.com/schema/bt http://www.mantis-tgi.com/schema/bt/mtgi-bt-1.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> <bt:manager/><bt:advice id="btAdvice"/>
<tx:advice id="txAdvice"/> <aop:config> <aop:pointcut id="trackedOperations" expression="execution(* com.mtgi..*Service(..))" /> <aop:advisor id="behaviorTrackingAdvisor" advice-ref="btAdvice" pointcut-ref="trackedOperations" order="1"/> <aop:advisor id="transactionAdvisor" advice-ref="txAdvice" pointcut-ref="trackedOperations" order="2"/>
</aop:config>
Example 3.5. Register MBeans on a JVM with multiple Beet applications
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bt="http://www.mantis-tgi.com/schema/bt/1.1" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.mantis-tgi.com/schema/bt http://www.mantis-tgi.com/schema/bt/mtgi-bt-1.1.xsd"> <bt:manager application="myapp"/> <!-- setup automatic export of annotated MBeans to the platform mbean server. Except where called out, most of this is boilerplate Spring/JMX configuration. --> <bean id="jmxAttributeSource" class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource"/> <bean id="jmxExporter" class="org.springframework.jmx.export.MBeanExporter"> <property name="assembler"> <bean class="org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler"> <property name="attributeSource" ref="jmxAttributeSource"/> </bean> </property> <property name="namingStrategy"> <bean class="com.mtgi.jmx.export.naming.ApplicationNamingStrategy"><property name="application" value="myapp"/> <property name="delegate"> <bean class="org.springframework.jmx.export.naming.MetadataNamingStrategy"> <property name="attributeSource" ref="jmxAttributeSource"/> </bean> </property> </bean> </property> <property name="autodetect" value="true"/> </bean>
![]() | Here we add a naming strategy which puts all detected MBeans in a group called "myapp", see the ApplicationNamingStrategy JavaDoc. The "delegate" property can be any other valid naming strategy supported by Spring, which defines how the rest of the MBean names are constructed. You can choose different names for each application to keep them in separate branches of the JVM's platform MBean tree. |