带有spectj和tapestry 5的NoAspectBoundException

发布于 2024-10-10 01:24:01 字数 4402 浏览 0 评论 0原文

我有一个使用 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< /a>.编译器似乎没有完全编织方面?我是 AspectJ 的新手,但我想知道这是否与 Tapestry5。虽然我知道 Tap5 使用 AOP。

正如我所说,这一切都工作得很好,直到我将一些东西移到一个单独的 Tapestry 自定义库中,该库现在是我的 Web 应用程序的依赖项。

I have a web project built with Tapestry 5.2.1. I have a simple logging aspect that I was using for tracing on this application. Everything was working fine until I started refactoring parts of the application and attempted to deploy it.

When I deploy the application, no matter what page I attempt to go to I get the following exception:

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

My aspect has remained unchanged and is this:

@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 + "]");
    }
}

During compilation everything works fine. I'm using the maven plugin to compile the aspects:

<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>

I've been working at this off and on for most of the day and haven't gotten anywhere. I'm not exactly understanding the NoAspectBoundException. It would seem that the compiler is not weaving the aspect completely? I'm new to AspectJ but I'm wondering if this is something to do with Tapestry5. Although I know that Tap5 uses AOP though.

As I said, this was all working as is just fine until I moved some things into a separate tapestry custom library that is now a dependency for my web app.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

清风疏影 2024-10-17 01:24:01

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

You are advising the aspect's constructor due to the unrestricted execution(*.new(..)) part of the pointcut. When the aspect is being instantiated, the advice doesn't have an instance of the aspect, hence the error. You should be able to fix this by adding !within([package of].TraceAspect).

久隐师 2024-10-17 01:24:01

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

I think we are having a conflict of AOP. AspectJ has done something to the code, and then Tapestry comes along and does something else ... including ignoring existing Class constructors on the component class and adding its own. I'm not sure how to get the two working together.

一抹淡然 2024-10-17 01:24:01

我知道现在回答这个问题已经太晚了。但据我了解,最好不要在挂毯上使用aspectj。如果您想使用它,则不得将 @Aspect 类定义为 Tapestry 组件。只需将类移动到另一个路径(除了页面包之外的任何地方)。

I know it is too late to answer this question. But as I understand it's better to don't use aspectj with the tapestry. If you want to use it you must not define the @Aspect class as a tapestry component. Just move the class to another path (anywhere except the pages package).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文