我有一个用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应用程序的依赖项。

最佳答案

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

07-24 09:46
查看更多