我有一组使用 Maven 构建的 AspectJ 1.6.12 和 Spring 3.1.2.RELEASE 在 JBoss 6.1.0.Final 上运行没有问题的 WAR。我们想在不久的将来迁移到 JBoss AS 7,所以我从源代码编译了 JBoss 7.1.3.Final。
在遇到单个 WAR 文件问题后,我决定将应用程序重新打包为 EAR 文件,这样我们的所有代码都将放在一个可再分发、可部署的单元中。
我无法让我们的分析方面正常工作。这是一个非常简单的方面,包含在我们的 EAR/lib 目录中的 JAR 中,它对使用 @Timed 注释注释的任何方法进行计时:
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;
}
}
请注意,注释在同一个包中。
这是方面的相关 Spring 配置文件,同样非常简单:
<?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>
EAR 中包含三个 WAR 文件,但现在只有一个使用这个方面,即 gdm-updater.WAR。当我尝试启动服务器时,出现如下错误:
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
我还尝试将 AspectJ 作为一个模块包含在内,这里是 EAR 中包含的 jboss-deployment-structure.xml 文件。
<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>
我什至尝试在 gdm-updater.war 中使用 Maven AspectJ 编译器插件在 gdm-updater.war 的 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>
我什么都做不了。我在网上搜索了答案并找到了几个链接,但似乎没有一个是相关的:
有人用 JBoss AS 7.1.1 final 运行 AspectJ 吗?- 不相关,因为我没有使用加载时编织
https://issues.jboss.org/browse/AS7-3681 - 不相关,因为我没有使用加载时编织或 AspectJ 作为 Java 代理
我考虑过加载时编织,但相关方面将很快扩展到包含“通用”jar 文件的其余部分中存在的一些功能,我无法将其分解为引导类路径。这意味着每次我们有一个新的方面,我们都必须重新配置服务器。
我究竟做错了什么?