与aspectj和tapestry 5的NoAspectBoundException

时间:2011-01-03 21:31:42

标签: java aop aspectj tapestry

我有一个使用Tapestry 5.2.1构建的Web项目。我有一个简单的日志记录方面,我用于跟踪此应用程序。一切正常,直到我开始重构部分应用程序并尝试部署它。

当我部署应用程序时,无论我尝试去哪个页面,我都会遇到以下异常:

Caused by: java.lang.RuntimeException: Exception assembling root component of page Index: Exception while initializing TraceAspect: org.aspectj.lang.NoAspectBoundException: TraceAspect
    at org.apache.tapestry5.internal.pageload.ComponentAssemblerImpl.performAssembleRootComponent(ComponentAssemblerImpl.java:124)
    at org.apache.tapestry5.internal.pageload.ComponentAssemblerImpl.access$000(ComponentAssemblerImpl.java:38)
    at org.apache.tapestry5.internal.pageload.ComponentAssemblerImpl$1.invoke(ComponentAssemblerImpl.java:82)
    at org.apache.tapestry5.internal.pageload.ComponentAssemblerImpl$1.invoke(ComponentAssemblerImpl.java:79)
    at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:65)
    ... 73 more
Caused by: org.aspectj.lang.NoAspectBoundException: Exception while initializing TraceAspect: org.aspectj.lang.NoAspectBoundException: TraceAspect
    at TraceAspect.aspectOf(TraceAspect.aj:1)
    at com.wex.rrt.wrightweb.reportrequest.webapp.pages.Index.initializer(Index.java:3)
    at com.wex.rrt.wrightweb.reportrequest.webapp.pages.Index.<init>(Index.java)
    at $Instantiator_12d4da06f67.newInstance($Instantiator_12d4da06f67.java)
    at org.apache.tapestry5.internal.structure.InternalComponentResourcesImpl.<init>(InternalComponentResourcesImpl.java:146)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.<init>(ComponentPageElementImpl.java:593)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.<init>(ComponentPageElementImpl.java:609)
    at org.apache.tapestry5.internal.pageload.ComponentAssemblerImpl.performAssembleRootComponent(ComponentAssemblerImpl.java:93)
    ... 77 more
Caused by: org.aspectj.lang.NoAspectBoundException: TraceAspect
    at TraceAspect.aspectOf(TraceAspect.aj:1)
    at AbstractLoggingAspect.<init>(AbstractLoggingAspect.aj:7)
    at TraceAspect.<init>(TraceAspect.aj:12)
    at TraceAspect.ajc$postClinit(TraceAspect.aj:1)
    at TraceAspect.<clinit>(TraceAspect.aj:1)
    ... 84 more

我的方面保持不变,是这样的:

@Aspect
public class TraceAspect {

    Logger logger = Logger.getLogger("trace");

    public TraceAspect() {
        logger.setLevel(Level.ALL);
    }

    /**
     * Will log every execution of
     * <ul>
     * <li>doEverything</li>
     * <li>doSomething</li>
     * </ul>
     * excluding any test classes.
     */
    @Pointcut("(execution(public void *(..)) || execution(*.new(..))) && !within(*Test) !within(com.aspects.*)")
    protected void logging() {
    }

    @Around("logging()")
    public void doThing(final ProceedingJoinPoint thisJoinPoint) throws Throwable {
        final String joinPointName = thisJoinPoint.getThis().getClass().getSimpleName() + "." + thisJoinPoint.getSignature().getName() + "()";
        logger.info("Entering [" + joinPointName + "]");
        thisJoinPoint.proceed();
        logger.info("Leaving  [" + joinPointName + "]");
    }
}

编译期间一切正常。我正在使用maven插件来编译方面:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <version>1.3</version>
    <configuration>
        <source>1.6</source>
        <target>1.6</target>
        <complianceLevel>1.6</complianceLevel>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>compile</goal> 
                <goal>test-compile</goal>
            </goals>
        </execution>
    </executions>
</plugin>

我一直在这个时间里一直工作,而且还没有到任何地方。我并不完全理解NoAspectBoundException。似乎编译器没有完全编织方面?我是AspectJ的新手,但我想知道这是否与Tapestry5有关。虽然我知道Tap5虽然使用AOP。

正如我所说,这一切都正常,直到我将一些内容移动到一个单独的挂毯自定义库中,该库现在是我的Web应用程序的依赖项。

2 个答案:

答案 0 :(得分:4)

由于切入点的execution(*.new(..))部分不受限制,您建议方面的构造函数。在实例化方面时,建议没有方面的实例,因此错误。您应该可以通过添加!within([package of].TraceAspect)来修复此问题。

答案 1 :(得分:0)

我认为我们正在发生AOP冲突。 AspectJ已经对代码做了一些事情,然后Tapestry出现并做了其他事情......包括忽略组件类上现有的类构造函数并添加自己的类构造函数。我不确定如何让两者一起工作。