I have a set of WARs that worked without problems on JBoss 6.1.0.Final that use AspectJ 1.6.12 and Spring 3.1.2.RELEASE, built with Maven. We would like to move to JBoss AS 7 in the near future, so I compiled JBoss 7.1.3.Final from source.
I decided to repackage the application as an EAR file after I had problems with individual WAR files, and so all of our code would be in one, redistributable, deployable unit.
I am having trouble getting our profiling aspect working. It is an extremely simple aspect contained in a JAR in our EAR/lib directory, that times any method annotated with the @Timed annotation:
package com.mycompany.toplayer.perf;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@Component
@Aspect
public class MethodTimerAdvice {
private Logger log = LoggerFactory.getLogger(getClass());
@SuppressWarnings("unchecked")
@Around(value="execution(@com.mycompany.toplayer.perf.Timed * *(..))")
public Object timeMethod(ProceedingJoinPoint pjp) throws Throwable
{
String methodName = pjp.getSignature().toShortString();
long start = System.currentTimeMillis();
Object ret = pjp.proceed();
long end = System.currentTimeMillis();
long total = end - start;
long used_mem = Runtime.getRuntime().totalMemory()
- Runtime.getRuntime().freeMemory();
long mem_gb = used_mem / (1024 * 1024);
log.trace("{} | {} | {}M | {} | {} | {}",
new Object[] {start, total,
mem_gb,
Thread.currentThread().getId(),
Thread.currentThread().getName(),
methodName}
);
return ret;
}
}
Note that the annotation is in the same package.
Here is the relevant Spring configuration file for the aspect, again it is very simple:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="com.mycompany" />
<aop:aspectj-autoproxy></aop:aspectj-autoproxy>
</beans>
There are three WAR files included in the EAR, but right now only one of them is using this aspect, gdm-updater.WAR. When I attempt to start the server, I get errors like this:
Caused by: java.lang.IllegalArgumentException: warning no match for this type name: Timed [Xlint:invalidAbsoluteTypeName]
at org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression(PointcutParser.java:301) [aspectjtools.jar:]
at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:207) [spring-aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.aop.aspectj.AspectJExpressionPointcut.getFallbackPointcutExpression(AspectJExpressionPointcut.java:358) [spring-aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.aop.aspectj.AspectJExpressionPointcut.getShadowMatch(AspectJExpressionPointcut.java:409) [spring-aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.aop.aspectj.AspectJExpressionPointcut.matches(AspectJExpressionPointcut.java:272) [spring-aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:226) [spring-aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:264) [spring-aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:296) [spring-aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findAdvisorsThatCanApply(AbstractAdvisorAutoProxyCreator.java:117) [spring-aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:87) [spring-aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:68) [spring-aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:359) [spring-aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:322) [spring-aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:407) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.postProcessObjectFromFactoryBean(AbstractAutowireCapableBeanFactory.java:1598) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:162) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]
... 28 more
I also tried including AspectJ as a module, and here is the jboss-deployment-structure.xml file included with the EAR.
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">
<deployment>
<exclusions>
<module name="org.hibernate" slot="main"/>
</exclusions>
</deployment>
<sub-deployment name="gdm-updater-1.2.0-SNAPSHOT.war">
<exclusions>
<module name="org.hibernate" slot="main"/>
</exclusions>
<dependencies>
<module name="org.aspectj.tools" slot="main" />
<module name="org.aspectj.weaver" slot="main" />
</dependencies>
</sub-deployment>
</jboss-deployment-structure>
I even tried using the Maven AspectJ compiler plugin in gdm-updater.war to do compile-time weaving in gdm-updater.war's pom.xml:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<configuration>
<showWeaveInfo>true</showWeaveInfo>
<source>${compiler.version}</source>
<target>${compiler.version}</target>
<Xlint>ignore</Xlint>
<complianceLevel>${compiler.version}</complianceLevel>
<encoding>UTF-8</encoding>
<verbose>false</verbose>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
I can't get anything working. I searched the web for answers and found a couple of links, but none seem to be relevant:
Has anyone run AspectJ with JBoss AS 7.1.1 final? - not relevant since I'm not using load-time weaving
https://issues.jboss.org/browse/AS7-3681 - not relevant since I'm not using load-time weaving or AspectJ as a Java agent
I've considered load-time weaving, but the aspect in question will soon be expanded to include some features present in the rest of that "common" jar file, and I can't break that out to the boot classpath. It would mean that every time we have a new aspect, we have to reconfigure the server.
What am I doing wrong?