开发者

NoAspectBoundException with aspectj and tapestry 5

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.


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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜